@opendatalabs/vana-sdk 0.1.0-alpha.82bbb39 → 0.1.0-alpha.899ca9d
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 +42 -0
- package/dist/browser-DY8XDblx.d.ts +241 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +309 -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 +1756 -1479
- package/dist/index.browser.js +37686 -35103
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +38174 -35582
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +1790 -1486
- package/dist/index.node.d.ts +1790 -1486
- package/dist/index.node.js +38402 -35813
- 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 +348 -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 +311 -0
- package/dist/node.js.map +1 -0
- package/dist/platform.browser.d.ts +3 -236
- package/dist/platform.browser.js +31 -8
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.cjs +72 -62
- 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 +72 -62
- package/dist/platform.js.map +1 -1
- package/dist/platform.node.cjs +72 -62
- package/dist/platform.node.cjs.map +1 -1
- package/dist/platform.node.d.cts +7 -236
- package/dist/platform.node.d.ts +7 -236
- package/dist/platform.node.js +72 -62
- package/dist/platform.node.js.map +1 -1
- package/package.json +17 -12
package/dist/platform.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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.ts","../src/platform/node.ts","../src/platform/shared/stream-utils.ts","../src/platform/utils.ts","../src/platform/browser-safe.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/**\n * Cross-platform base64 encoding\n * Works in both Node.js and browser environments\n *\n * @param str The string to encode\n * @returns Base64 encoded string\n */\nexport function toBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"utf8\").toString(\"base64\");\n } else if (typeof btoa !== \"undefined\") {\n // Browser environment\n return btoa(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n while (i < str.length) {\n const a = str.charCodeAt(i++);\n const b = i < str.length ? str.charCodeAt(i++) : 0;\n const c = i < str.length ? str.charCodeAt(i++) : 0;\n\n const bitmap = (a << 16) | (b << 8) | c;\n\n result += chars.charAt((bitmap >> 18) & 63);\n result += chars.charAt((bitmap >> 12) & 63);\n result += i - 2 < str.length ? chars.charAt((bitmap >> 6) & 63) : \"=\";\n result += i - 1 < str.length ? chars.charAt(bitmap & 63) : \"=\";\n }\n return result;\n }\n}\n\n/**\n * Cross-platform base64 decoding\n * Works in both Node.js and browser environments\n *\n * @param str The base64 string to decode\n * @returns Decoded string\n */\nexport function fromBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"base64\").toString(\"utf8\");\n } else if (typeof atob !== \"undefined\") {\n // Browser environment\n return atob(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n\n // Remove any characters not in the base64 character set\n str = str.replace(/[^A-Za-z0-9+/]/g, \"\");\n\n while (i < str.length) {\n const encoded1 = chars.indexOf(str.charAt(i++));\n const encoded2 = chars.indexOf(str.charAt(i++));\n const encoded3 = chars.indexOf(str.charAt(i++));\n const encoded4 = chars.indexOf(str.charAt(i++));\n\n const bitmap =\n (encoded1 << 18) | (encoded2 << 12) | (encoded3 << 6) | encoded4;\n\n result += String.fromCharCode((bitmap >> 16) & 255);\n if (encoded3 !== 64) result += String.fromCharCode((bitmap >> 8) & 255);\n if (encoded4 !== 64) result += String.fromCharCode(bitmap & 255);\n }\n return result;\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 VanaCacheAdapter,\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 * Browser implementation of cache operations using sessionStorage\n */\nclass BrowserCacheAdapter implements VanaCacheAdapter {\n private readonly prefix = \"vana_cache_\";\n\n get(key: string): string | null {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return null;\n }\n return sessionStorage.getItem(this.prefix + key);\n } catch {\n return null;\n }\n }\n\n set(key: string, value: string): void {\n try {\n if (typeof sessionStorage !== \"undefined\") {\n sessionStorage.setItem(this.prefix + key, value);\n }\n } catch {\n // Silently ignore storage errors (quota exceeded, etc.)\n }\n }\n\n delete(key: string): void {\n try {\n if (typeof sessionStorage !== \"undefined\") {\n sessionStorage.removeItem(this.prefix + key);\n }\n } catch {\n // Silently ignore storage errors\n }\n }\n\n clear(): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n\n const keys = Object.keys(sessionStorage);\n for (const key of keys) {\n if (key.startsWith(this.prefix)) {\n sessionStorage.removeItem(key);\n }\n }\n } catch {\n // Silently ignore storage errors\n }\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 cache: VanaCacheAdapter;\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 this.cache = new BrowserCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const browserPlatformAdapter: VanaPlatformAdapter =\n new BrowserPlatformAdapter();\n","/**\n * Platform adapters entry point\n *\n * This module provides platform-specific utilities for different environments.\n * Use this when you need platform detection or adapter creation.\n */\n\n// Export platform adapters - these will be environment-specific\nexport { BrowserPlatformAdapter } from \"./platform/browser\";\nexport { NodePlatformAdapter } from \"./platform/node\";\n\n// Export platform interface\nexport type { VanaPlatformAdapter } from \"./platform/interface\";\n\n// Export platform utilities\nexport {\n detectPlatform,\n createPlatformAdapter,\n createPlatformAdapterFor,\n isPlatformSupported,\n getPlatformCapabilities,\n} from \"./platform/utils\";\n\n// Export browser-safe utilities\nexport {\n createNodePlatformAdapter,\n createBrowserPlatformAdapter,\n createPlatformAdapterSafe,\n} from \"./platform/browser-safe\";\n","/**\n * Node.js implementation of the Vana Platform Adapter\n *\n * This implementation uses Node.js-specific libraries and configurations\n * to provide crypto, PGP, and HTTP functionality.\n */\n\nimport { randomBytes } from \"crypto\";\nimport * as openpgp from \"openpgp\";\nimport {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\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\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\n\n// Eccrypto type definitions removed - using dynamic imports instead\n\n// Dynamically import eccrypto for Node.js\nlet eccrypto: {\n encrypt: (\n publicKey: Buffer,\n message: Buffer,\n ) => Promise<{\n iv: Buffer;\n ephemPublicKey: Buffer;\n ciphertext: Buffer;\n mac: Buffer;\n }>;\n decrypt: (\n privateKey: Buffer,\n encrypted: {\n iv: Buffer;\n ephemPublicKey: Buffer;\n ciphertext: Buffer;\n mac: Buffer;\n },\n ) => Promise<Buffer>;\n getPublicCompressed: (privateKey: Buffer) => Buffer;\n} | null = null;\n\n// Lazy load eccrypto\n/**\n * Lazy loads the eccrypto library for Node.js crypto operations\n *\n * @returns Promise resolving to the eccrypto library instance\n */\nasync function getEccrypto() {\n if (!eccrypto) {\n try {\n // Import the eccrypto library for Node.js\n const eccryptoLib = await import(\"eccrypto\");\n\n eccrypto = {\n encrypt: eccryptoLib.encrypt,\n decrypt: eccryptoLib.decrypt,\n getPublicCompressed: eccryptoLib.getPublicCompressed,\n };\n } catch (error) {\n throw new Error(`Failed to load eccrypto library: ${error}`);\n }\n }\n return eccrypto;\n}\n\n/**\n * Node.js implementation of crypto operations using secp256k1\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n const eccryptoLib = await getEccrypto();\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccryptoLib.encrypt(publicKey, message);\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 const eccryptoLib = await getEccrypto();\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 const decrypted = await eccryptoLib.decrypt(\n privateKeyBuffer,\n encryptedObj,\n );\n return decrypted.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 const eccryptoLib = await getEccrypto();\n const privateKey = randomBytes(32);\n const publicKey = eccryptoLib.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 const eccryptoLib = await getEccrypto();\n\n // Use shared utility to process public key\n const uncompressedKey = processWalletPublicKey(publicKey);\n\n const encrypted = await eccryptoLib.encrypt(\n uncompressedKey,\n Buffer.from(data),\n );\n\n // Concatenate all components and return as hex (same format as browser)\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 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 const eccryptoLib = await getEccrypto();\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 eccryptoLib.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 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 // In Node.js, the encrypted result is already a Uint8Array\n if (encrypted instanceof Uint8Array) {\n return encrypted;\n }\n\n // If it's a stream (should not happen with format: \"binary\"), read it\n if (\n encrypted &&\n typeof encrypted === \"object\" &&\n \"getReader\" in encrypted\n ) {\n return await streamToUint8Array(\n encrypted as ReadableStream<Uint8Array>,\n );\n }\n\n throw new Error(\"Unexpected encrypted data format\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with password\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\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 wrapCryptoError(\"decrypt with password\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of PGP operations using openpgp with Node-specific configuration\n */\nclass NodePGPAdapter 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 wrapCryptoError(\"PGP encryption\", 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 wrapCryptoError(\"PGP decryption\", 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 * Node.js implementation of HTTP operations using node-fetch or native fetch\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch(url, options);\n }\n\n throw new Error(\"No fetch implementation available in Node.js environment\");\n }\n}\n\n/**\n * Node.js implementation of cache operations using in-memory Map with TTL\n */\nclass NodeCacheAdapter implements VanaCacheAdapter {\n private cache = new Map<string, { value: string; expires: number }>();\n private readonly defaultTtl = 2 * 60 * 60 * 1000; // 2 hours in milliseconds\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string): void {\n this.cache.set(key, {\n value,\n expires: Date.now() + this.defaultTtl,\n });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Complete Node.js platform adapter implementation\n */\nexport class NodePlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n cache: VanaCacheAdapter;\n platform: \"node\" = \"node\" as const;\n\n constructor() {\n this.crypto = new NodeCryptoAdapter();\n this.pgp = new NodePGPAdapter();\n this.http = new NodeHttpAdapter();\n this.cache = new NodeCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const nodePlatformAdapter: VanaPlatformAdapter =\n new NodePlatformAdapter();\n","/**\n * Shared stream 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 * Convert ReadableStream to Uint8Array\n * Used primarily in Node.js environment where OpenPGP may return streams\n *\n * @param stream The ReadableStream to convert\n * @returns Promise resolving to Uint8Array containing all stream data\n */\nexport async function streamToUint8Array(\n stream: ReadableStream<Uint8Array>,\n): Promise<Uint8Array> {\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n // Concatenate all chunks\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n\n return result;\n}\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","/**\n * Browser-safe exports for platform adapters\n *\n * This file provides browser-safe exports that avoid importing Node.js dependencies\n * when bundling for browser environments.\n */\n\nimport type { VanaPlatformAdapter } from \"./interface\";\nimport { BrowserPlatformAdapter } from \"./browser\";\n\n/**\n * Dynamically imports the NodePlatformAdapter only when needed\n * This prevents Node.js modules from being bundled in browser builds\n *\n * @returns Promise resolving to a NodePlatformAdapter instance\n * @throws {Error} If running in a browser environment\n */\nexport async function createNodePlatformAdapter(): Promise<VanaPlatformAdapter> {\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 during bundling\n const moduleName = \"./node\";\n const { NodePlatformAdapter } = await import(moduleName);\n return new NodePlatformAdapter();\n}\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-safe platform adapter factory\n *\n * @returns Promise resolving to the appropriate platform adapter\n */\nexport async function createPlatformAdapterSafe(): Promise<VanaPlatformAdapter> {\n // Check if we're in a browser environment\n if (typeof window !== \"undefined\") {\n return createBrowserPlatformAdapter();\n }\n\n // Check for Node.js environment\n if (\n typeof process !== \"undefined\" &&\n process.versions &&\n process.versions.node\n ) {\n // Only attempt Node.js import if we're not in a browser environment\n if (typeof window === \"undefined\") {\n return await createNodePlatformAdapter();\n }\n }\n\n // Default to browser if we can't determine\n return createBrowserPlatformAdapter();\n}\n\n// Export types\nexport type { VanaPlatformAdapter } from \"./interface\";\nexport type { BrowserPlatformAdapter } from \"./browser\";\n// NodePlatformAdapter type is available through dynamic import to avoid bundling Node.js dependencies\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,SAAS,yBAAyB,iBAAyB;AAChE,SAAO;AAAA,IACL,IAAI,gBAAgB,MAAM,GAAG,EAAE;AAAA,IAC/B,gBAAgB,gBAAgB,MAAM,IAAI,EAAE;AAAA;AAAA,IAC5C,YAAY,gBAAgB,MAAM,IAAI,GAAG;AAAA,IACzC,KAAK,gBAAgB,MAAM,GAAG;AAAA,EAChC;AACF;AAvDA;AAAA;AAAA;AAAA;AAAA;;;ACyBO,SAAS,qBAAqB,SAIlC;AACD,SAAO;AAAA,IACL,MAAM,SAAS,QAAQ;AAAA,IACvB,OAAO,SAAS,SAAS;AAAA,IACzB,YAAY,SAAS;AAAA,EACvB;AACF;AAYO,SAAS,mBAAmB,SAIhC;AACD,QAAM,EAAE,MAAM,OAAO,WAAW,IAAI,qBAAqB,OAAO;AAEhE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,CAA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C7B;AAOO,SAAS,0BAA0B;AACxC,QAAM,WAAW,eAAe;AAEhC,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,MACN,WAAW,OAAO,WAAW,eAAe,OAAO;AAAA,MACnD,YACE,OAAO,YAAY,eACnB,QAAQ,YACR,QAAQ,SAAS;AAAA,IACrB;AAAA,IACA,OACE,OAAO,UAAU,eAAe,OAAO,WAAW,UAAU;AAAA,IAC9D,SAAS,OAAO,mBAAmB;AAAA,EACrC;AACF;;;AC5HA;AASA,eAAsB,4BAA0D;AAE9E,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,QAAM,aAAa;AACnB,QAAM,EAAE,qBAAAC,qBAAoB,IAAI,MAAM,OAAO;AAC7C,SAAO,IAAIA,qBAAoB;AACjC;AAOO,SAAS,+BAAoD;AAClE,SAAO,IAAI,uBAAuB;AACpC;AAOA,eAAsB,4BAA0D;AAE9E,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,6BAA6B;AAAA,EACtC;AAGA,MACE,OAAO,YAAY,eACnB,QAAQ,YACR,QAAQ,SAAS,MACjB;AAEA,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO,MAAM,0BAA0B;AAAA,IACzC;AAAA,EACF;AAGA,SAAO,6BAA6B;AACtC;","names":["eccrypto","openpgp","openpgp","NodePlatformAdapter","BrowserPlatformAdapter","NodePlatformAdapter"]}
|
|
1
|
+
{"version":3,"sources":["../src/platform/shared/crypto-utils.ts","../src/platform/shared/pgp-utils.ts","../src/platform/shared/error-utils.ts","../src/utils/lazy-import.ts","../src/platform/browser.ts","../src/platform.ts","../src/platform/node.ts","../src/platform/shared/stream-utils.ts","../src/platform/utils.ts","../src/platform/browser-safe.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/**\n * Cross-platform base64 encoding\n * Works in both Node.js and browser environments\n *\n * @param str The string to encode\n * @returns Base64 encoded string\n */\nexport function toBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"utf8\").toString(\"base64\");\n } else if (typeof btoa !== \"undefined\") {\n // Browser environment\n return btoa(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n while (i < str.length) {\n const a = str.charCodeAt(i++);\n const b = i < str.length ? str.charCodeAt(i++) : 0;\n const c = i < str.length ? str.charCodeAt(i++) : 0;\n\n const bitmap = (a << 16) | (b << 8) | c;\n\n result += chars.charAt((bitmap >> 18) & 63);\n result += chars.charAt((bitmap >> 12) & 63);\n result += i - 2 < str.length ? chars.charAt((bitmap >> 6) & 63) : \"=\";\n result += i - 1 < str.length ? chars.charAt(bitmap & 63) : \"=\";\n }\n return result;\n }\n}\n\n/**\n * Cross-platform base64 decoding\n * Works in both Node.js and browser environments\n *\n * @param str The base64 string to decode\n * @returns Decoded string\n */\nexport function fromBase64(str: string): string {\n if (typeof Buffer !== \"undefined\") {\n // Node.js environment\n return Buffer.from(str, \"base64\").toString(\"utf8\");\n } else if (typeof atob !== \"undefined\") {\n // Browser environment\n return atob(str);\n } else {\n // Fallback manual implementation\n const chars =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n let result = \"\";\n let i = 0;\n\n // Remove any characters not in the base64 character set\n str = str.replace(/[^A-Za-z0-9+/]/g, \"\");\n\n while (i < str.length) {\n const encoded1 = chars.indexOf(str.charAt(i++));\n const encoded2 = chars.indexOf(str.charAt(i++));\n const encoded3 = chars.indexOf(str.charAt(i++));\n const encoded4 = chars.indexOf(str.charAt(i++));\n\n const bitmap =\n (encoded1 << 18) | (encoded2 << 12) | (encoded3 << 6) | encoded4;\n\n result += String.fromCharCode((bitmap >> 16) & 255);\n if (encoded3 !== 64) result += String.fromCharCode((bitmap >> 8) & 255);\n if (encoded4 !== 64) result += String.fromCharCode(bitmap & 255);\n }\n return result;\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 * Utility for lazy-loading modules to avoid Turbopack TDZ issues\n *\n * WARNING: This is a workaround for Turbopack's strict module initialization.\n * Dependencies that access globals during init must be dynamically imported.\n */\n\n/**\n * Creates a lazy import function that caches the promise (not the module)\n * to avoid race conditions on concurrent first calls\n *\n * @param importFn - Function that returns a dynamic import promise\n * @returns Function that returns the cached import promise\n *\n * @example\n * const getOpenPGP = lazyImport(() => import('openpgp'));\n * const openpgp = await getOpenPGP();\n */\nexport function lazyImport<T>(importFn: () => Promise<T>): () => Promise<T> {\n let cached: Promise<T> | null = null;\n\n return () => {\n if (!cached) {\n cached = importFn().catch((err) => {\n // Clear cache on error so next attempt can retry\n cached = null;\n throw new Error(\"Failed to load module\", { cause: err });\n });\n }\n return cached;\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 * WARNING: Dependencies that access globals during init\n * MUST be dynamically imported to support Turbopack.\n * See: https://github.com/vercel/next.js/issues/82632\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\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\";\nimport { lazyImport } from \"../utils/lazy-import\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\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 getOpenPGP();\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 getOpenPGP();\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 openpgp = await getOpenPGP();\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 openpgp = await getOpenPGP();\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 const openpgp = await getOpenPGP();\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 * Browser implementation of cache operations using sessionStorage\n */\nclass BrowserCacheAdapter implements VanaCacheAdapter {\n private readonly prefix = \"vana_cache_\";\n\n get(key: string): string | null {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return null;\n }\n return sessionStorage.getItem(this.prefix + key);\n } catch {\n return null;\n }\n }\n\n set(key: string, value: string): void {\n try {\n if (typeof sessionStorage !== \"undefined\") {\n sessionStorage.setItem(this.prefix + key, value);\n }\n } catch {\n // Silently ignore storage errors (quota exceeded, etc.)\n }\n }\n\n delete(key: string): void {\n try {\n if (typeof sessionStorage !== \"undefined\") {\n sessionStorage.removeItem(this.prefix + key);\n }\n } catch {\n // Silently ignore storage errors\n }\n }\n\n clear(): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n\n const keys = Object.keys(sessionStorage);\n for (const key of keys) {\n if (key.startsWith(this.prefix)) {\n sessionStorage.removeItem(key);\n }\n }\n } catch {\n // Silently ignore storage errors\n }\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 cache: VanaCacheAdapter;\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 this.cache = new BrowserCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const browserPlatformAdapter: VanaPlatformAdapter =\n new BrowserPlatformAdapter();\n","/**\n * Platform adapters entry point\n *\n * This module provides platform-specific utilities for different environments.\n * Use this when you need platform detection or adapter creation.\n */\n\n// Export platform adapters - these will be environment-specific\nexport { BrowserPlatformAdapter } from \"./platform/browser\";\nexport { NodePlatformAdapter } from \"./platform/node\";\n\n// Export platform interface\nexport type { VanaPlatformAdapter } from \"./platform/interface\";\n\n// Export platform utilities\nexport {\n detectPlatform,\n createPlatformAdapter,\n createPlatformAdapterFor,\n isPlatformSupported,\n getPlatformCapabilities,\n} from \"./platform/utils\";\n\n// Export browser-safe utilities\nexport {\n createNodePlatformAdapter,\n createBrowserPlatformAdapter,\n createPlatformAdapterSafe,\n} from \"./platform/browser-safe\";\n","/**\n * Node.js implementation of the Vana Platform Adapter\n *\n * WARNING: Dependencies that access globals during init\n * MUST be dynamically imported to support Turbopack.\n * See: https://github.com/vercel/next.js/issues/82632\n */\n\nimport type {\n VanaPlatformAdapter,\n VanaCryptoAdapter,\n VanaPGPAdapter,\n VanaHttpAdapter,\n VanaCacheAdapter,\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\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\nconst getEccrypto = lazyImport(() => import(\"eccrypto\"));\n\n/**\n * Node.js implementation of crypto operations using secp256k1\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n async encryptWithPublicKey(\n data: string,\n publicKeyHex: string,\n ): Promise<string> {\n try {\n const eccrypto = await getEccrypto();\n const publicKey = Buffer.from(publicKeyHex, \"hex\");\n const message = Buffer.from(data, \"utf8\");\n\n const encrypted = await eccrypto.encrypt(publicKey, message);\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 const eccrypto = await getEccrypto();\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 const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);\n return decrypted.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 const eccrypto = await getEccrypto();\n const privateKey = eccrypto.generatePrivate();\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 const eccrypto = await getEccrypto();\n\n // Use shared utility to process public key\n const uncompressedKey = processWalletPublicKey(publicKey);\n\n const encrypted = await eccrypto.encrypt(\n uncompressedKey,\n Buffer.from(data),\n );\n\n // Concatenate all components and return as hex (same format as browser)\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 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 const eccrypto = await getEccrypto();\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 const openpgp = await getOpenPGP();\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 // In Node.js, the encrypted result is already a Uint8Array\n if (encrypted instanceof Uint8Array) {\n return encrypted;\n }\n\n // If it's a stream (should not happen with format: \"binary\"), read it\n if (\n encrypted &&\n typeof encrypted === \"object\" &&\n \"getReader\" in encrypted\n ) {\n return await streamToUint8Array(\n encrypted as ReadableStream<Uint8Array>,\n );\n }\n\n throw new Error(\"Unexpected encrypted data format\");\n } catch (error) {\n throw wrapCryptoError(\"encrypt with password\", error);\n }\n }\n\n async decryptWithPassword(\n encryptedData: Uint8Array,\n password: string,\n ): Promise<Uint8Array> {\n try {\n const openpgp = await getOpenPGP();\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 wrapCryptoError(\"decrypt with password\", error);\n }\n }\n}\n\n/**\n * Node.js implementation of PGP operations using openpgp with Node-specific configuration\n */\nclass NodePGPAdapter implements VanaPGPAdapter {\n async encrypt(data: string, publicKeyArmored: string): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\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 wrapCryptoError(\"PGP encryption\", error);\n }\n }\n\n async decrypt(\n encryptedData: string,\n privateKeyArmored: string,\n ): Promise<string> {\n try {\n const openpgp = await getOpenPGP();\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 wrapCryptoError(\"PGP decryption\", 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 const openpgp = await getOpenPGP();\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 * Node.js implementation of HTTP operations using node-fetch or native fetch\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n async fetch(url: string, options?: RequestInit): Promise<Response> {\n if (typeof globalThis.fetch !== \"undefined\") {\n return globalThis.fetch(url, options);\n }\n\n throw new Error(\"No fetch implementation available in Node.js environment\");\n }\n}\n\n/**\n * Node.js implementation of cache operations using in-memory Map with TTL\n */\nclass NodeCacheAdapter implements VanaCacheAdapter {\n private cache = new Map<string, { value: string; expires: number }>();\n private readonly defaultTtl = 2 * 60 * 60 * 1000; // 2 hours in milliseconds\n\n get(key: string): string | null {\n const entry = this.cache.get(key);\n if (!entry) {\n return null;\n }\n\n // Check if expired\n if (Date.now() > entry.expires) {\n this.cache.delete(key);\n return null;\n }\n\n return entry.value;\n }\n\n set(key: string, value: string): void {\n this.cache.set(key, {\n value,\n expires: Date.now() + this.defaultTtl,\n });\n }\n\n delete(key: string): void {\n this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n}\n\n/**\n * Complete Node.js platform adapter implementation\n */\nexport class NodePlatformAdapter implements VanaPlatformAdapter {\n crypto: VanaCryptoAdapter;\n pgp: VanaPGPAdapter;\n http: VanaHttpAdapter;\n cache: VanaCacheAdapter;\n platform: \"node\" = \"node\" as const;\n\n constructor() {\n this.crypto = new NodeCryptoAdapter();\n this.pgp = new NodePGPAdapter();\n this.http = new NodeHttpAdapter();\n this.cache = new NodeCacheAdapter();\n }\n}\n\n/**\n * Default instance export for backwards compatibility\n */\nexport const nodePlatformAdapter: VanaPlatformAdapter =\n new NodePlatformAdapter();\n","/**\n * Shared stream 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 * Convert ReadableStream to Uint8Array\n * Used primarily in Node.js environment where OpenPGP may return streams\n *\n * @param stream The ReadableStream to convert\n * @returns Promise resolving to Uint8Array containing all stream data\n */\nexport async function streamToUint8Array(\n stream: ReadableStream<Uint8Array>,\n): Promise<Uint8Array> {\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n // Concatenate all chunks\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n\n return result;\n}\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","/**\n * Browser-safe exports for platform adapters\n *\n * This file provides browser-safe exports that avoid importing Node.js dependencies\n * when bundling for browser environments.\n */\n\nimport type { VanaPlatformAdapter } from \"./interface\";\nimport { BrowserPlatformAdapter } from \"./browser\";\n\n/**\n * Dynamically imports the NodePlatformAdapter only when needed\n * This prevents Node.js modules from being bundled in browser builds\n *\n * @returns Promise resolving to a NodePlatformAdapter instance\n * @throws {Error} If running in a browser environment\n */\nexport async function createNodePlatformAdapter(): Promise<VanaPlatformAdapter> {\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 during bundling\n const moduleName = \"./node\";\n const { NodePlatformAdapter } = await import(moduleName);\n return new NodePlatformAdapter();\n}\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-safe platform adapter factory\n *\n * @returns Promise resolving to the appropriate platform adapter\n */\nexport async function createPlatformAdapterSafe(): Promise<VanaPlatformAdapter> {\n // Check if we're in a browser environment\n if (typeof window !== \"undefined\") {\n return createBrowserPlatformAdapter();\n }\n\n // Check for Node.js environment\n if (\n typeof process !== \"undefined\" &&\n process.versions &&\n process.versions.node\n ) {\n // Only attempt Node.js import if we're not in a browser environment\n if (typeof window === \"undefined\") {\n return await createNodePlatformAdapter();\n }\n }\n\n // Default to browser if we can't determine\n return createBrowserPlatformAdapter();\n}\n\n// Export types\nexport type { VanaPlatformAdapter } from \"./interface\";\nexport type { BrowserPlatformAdapter } from \"./browser\";\n// NodePlatformAdapter type is available through dynamic import to avoid bundling Node.js dependencies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,UAAM,IAAI;AAAA,MACR,yCAAyC,YAAY,KAAK,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,IACpH;AAAA,EACF;AACF;AAQO,SAAS,oBAAoB,cAAqC;AACvE,QAAM,kBAAkB,eAAe;AACvC,SAAO,oBAAoB;AAC7B;AAOO,SAAS,0BAA0B;AACxC,QAAM,WAAW,eAAe;AAEhC,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,MACN,WAAW,OAAO,WAAW,eAAe,OAAO;AAAA,MACnD,YACE,OAAO,YAAY,eACnB,QAAQ,YACR,QAAQ,SAAS;AAAA,IACrB;AAAA,IACA,OACE,OAAO,UAAU,eAAe,OAAO,WAAW,UAAU;AAAA,IAC9D,SAAS,OAAO,mBAAmB;AAAA,EACrC;AACF;;;AC5HA;AASA,eAAsB,4BAA0D;AAE9E,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,QAAM,aAAa;AACnB,QAAM,EAAE,qBAAAC,qBAAoB,IAAI,MAAM,OAAO;AAC7C,SAAO,IAAIA,qBAAoB;AACjC;AAOO,SAAS,+BAAoD;AAClE,SAAO,IAAI,uBAAuB;AACpC;AAOA,eAAsB,4BAA0D;AAE9E,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,6BAA6B;AAAA,EACtC;AAGA,MACE,OAAO,YAAY,eACnB,QAAQ,YACR,QAAQ,SAAS,MACjB;AAEA,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO,MAAM,0BAA0B;AAAA,IACzC;AAAA,EACF;AAGA,SAAO,6BAA6B;AACtC;","names":["getOpenPGP","NodePlatformAdapter","BrowserPlatformAdapter","NodePlatformAdapter"]}
|
package/dist/platform.d.cts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { BrowserPlatformAdapter,
|
|
1
|
+
export { BrowserPlatformAdapter, createBrowserPlatformAdapter, createNodePlatformAdapter, createPlatformAdapter, createPlatformAdapterFor, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported } from './platform.node.cjs';
|
|
2
|
+
export { N as NodePlatformAdapter, V as VanaPlatformAdapter } from './node-D9-F9uEP.cjs';
|
package/dist/platform.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { BrowserPlatformAdapter,
|
|
1
|
+
export { BrowserPlatformAdapter, createBrowserPlatformAdapter, createNodePlatformAdapter, createPlatformAdapter, createPlatformAdapterFor, createPlatformAdapterSafe, detectPlatform, getPlatformCapabilities, isPlatformSupported } from './platform.node.js';
|
|
2
|
+
export { N as NodePlatformAdapter, V as VanaPlatformAdapter } from './node-D9-F9uEP.js';
|
package/dist/platform.js
CHANGED
|
@@ -75,26 +75,46 @@ var init_error_utils = __esm({
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
// src/utils/lazy-import.ts
|
|
79
|
+
function lazyImport(importFn) {
|
|
80
|
+
let cached = null;
|
|
81
|
+
return () => {
|
|
82
|
+
if (!cached) {
|
|
83
|
+
cached = importFn().catch((err) => {
|
|
84
|
+
cached = null;
|
|
85
|
+
throw new Error("Failed to load module", { cause: err });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return cached;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
var init_lazy_import = __esm({
|
|
92
|
+
"src/utils/lazy-import.ts"() {
|
|
93
|
+
"use strict";
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
78
97
|
// src/platform/browser.ts
|
|
79
98
|
var browser_exports = {};
|
|
80
99
|
__export(browser_exports, {
|
|
81
100
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
82
101
|
browserPlatformAdapter: () => browserPlatformAdapter
|
|
83
102
|
});
|
|
84
|
-
|
|
85
|
-
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
103
|
+
var getOpenPGP, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
86
104
|
var init_browser = __esm({
|
|
87
105
|
"src/platform/browser.ts"() {
|
|
88
106
|
"use strict";
|
|
89
107
|
init_crypto_utils();
|
|
90
108
|
init_pgp_utils();
|
|
91
109
|
init_error_utils();
|
|
110
|
+
init_lazy_import();
|
|
111
|
+
getOpenPGP = lazyImport(() => import("openpgp"));
|
|
92
112
|
BrowserCryptoAdapter = class {
|
|
93
113
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
94
114
|
try {
|
|
95
|
-
const
|
|
115
|
+
const eccrypto = await import("eccrypto-js");
|
|
96
116
|
const publicKeyBuffer = Buffer.from(publicKeyHex, "hex");
|
|
97
|
-
const encrypted = await
|
|
117
|
+
const encrypted = await eccrypto.encrypt(
|
|
98
118
|
publicKeyBuffer,
|
|
99
119
|
Buffer.from(data, "utf8")
|
|
100
120
|
);
|
|
@@ -111,12 +131,12 @@ var init_browser = __esm({
|
|
|
111
131
|
}
|
|
112
132
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
113
133
|
try {
|
|
114
|
-
const
|
|
134
|
+
const eccrypto = await import("eccrypto-js");
|
|
115
135
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
116
136
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
117
137
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
118
138
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
119
|
-
const decryptedBuffer = await
|
|
139
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
120
140
|
privateKeyBuffer,
|
|
121
141
|
encryptedObj
|
|
122
142
|
);
|
|
@@ -127,11 +147,11 @@ var init_browser = __esm({
|
|
|
127
147
|
}
|
|
128
148
|
async generateKeyPair() {
|
|
129
149
|
try {
|
|
130
|
-
const
|
|
150
|
+
const eccrypto = await import("eccrypto-js");
|
|
131
151
|
const privateKeyBytes = new Uint8Array(32);
|
|
132
152
|
crypto.getRandomValues(privateKeyBytes);
|
|
133
153
|
const privateKey = Buffer.from(privateKeyBytes);
|
|
134
|
-
const publicKey =
|
|
154
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
135
155
|
return {
|
|
136
156
|
privateKey: privateKey.toString("hex"),
|
|
137
157
|
publicKey: publicKey.toString("hex")
|
|
@@ -142,9 +162,9 @@ var init_browser = __esm({
|
|
|
142
162
|
}
|
|
143
163
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
144
164
|
try {
|
|
145
|
-
const
|
|
165
|
+
const eccrypto = await import("eccrypto-js");
|
|
146
166
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
147
|
-
const encryptedBuffer = await
|
|
167
|
+
const encryptedBuffer = await eccrypto.encrypt(
|
|
148
168
|
uncompressedKey,
|
|
149
169
|
Buffer.from(data)
|
|
150
170
|
);
|
|
@@ -161,12 +181,12 @@ var init_browser = __esm({
|
|
|
161
181
|
}
|
|
162
182
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
163
183
|
try {
|
|
164
|
-
const
|
|
184
|
+
const eccrypto = await import("eccrypto-js");
|
|
165
185
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
166
186
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
167
187
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
168
188
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
169
|
-
const decryptedBuffer = await
|
|
189
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
170
190
|
privateKeyBuffer,
|
|
171
191
|
encryptedObj
|
|
172
192
|
);
|
|
@@ -177,11 +197,11 @@ var init_browser = __esm({
|
|
|
177
197
|
}
|
|
178
198
|
async encryptWithPassword(data, password) {
|
|
179
199
|
try {
|
|
180
|
-
const
|
|
181
|
-
const message = await
|
|
200
|
+
const openpgp = await getOpenPGP();
|
|
201
|
+
const message = await openpgp.createMessage({
|
|
182
202
|
binary: data
|
|
183
203
|
});
|
|
184
|
-
const encrypted = await
|
|
204
|
+
const encrypted = await openpgp.encrypt({
|
|
185
205
|
message,
|
|
186
206
|
passwords: [password],
|
|
187
207
|
format: "binary"
|
|
@@ -195,11 +215,11 @@ var init_browser = __esm({
|
|
|
195
215
|
}
|
|
196
216
|
async decryptWithPassword(encryptedData, password) {
|
|
197
217
|
try {
|
|
198
|
-
const
|
|
199
|
-
const message = await
|
|
218
|
+
const openpgp = await getOpenPGP();
|
|
219
|
+
const message = await openpgp.readMessage({
|
|
200
220
|
binaryMessage: encryptedData
|
|
201
221
|
});
|
|
202
|
-
const { data: decrypted } = await
|
|
222
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
203
223
|
message,
|
|
204
224
|
passwords: [password],
|
|
205
225
|
format: "binary"
|
|
@@ -213,6 +233,7 @@ var init_browser = __esm({
|
|
|
213
233
|
BrowserPGPAdapter = class {
|
|
214
234
|
async encrypt(data, publicKeyArmored) {
|
|
215
235
|
try {
|
|
236
|
+
const openpgp = await getOpenPGP();
|
|
216
237
|
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
217
238
|
const encrypted = await openpgp.encrypt({
|
|
218
239
|
message: await openpgp.createMessage({ text: data }),
|
|
@@ -228,6 +249,7 @@ var init_browser = __esm({
|
|
|
228
249
|
}
|
|
229
250
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
230
251
|
try {
|
|
252
|
+
const openpgp = await getOpenPGP();
|
|
231
253
|
const privateKey = await openpgp.readPrivateKey({
|
|
232
254
|
armoredKey: privateKeyArmored
|
|
233
255
|
});
|
|
@@ -245,6 +267,7 @@ var init_browser = __esm({
|
|
|
245
267
|
}
|
|
246
268
|
async generateKeyPair(options) {
|
|
247
269
|
try {
|
|
270
|
+
const openpgp = await getOpenPGP();
|
|
248
271
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
249
272
|
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
250
273
|
return { publicKey, privateKey };
|
|
@@ -328,8 +351,6 @@ init_browser();
|
|
|
328
351
|
init_crypto_utils();
|
|
329
352
|
init_pgp_utils();
|
|
330
353
|
init_error_utils();
|
|
331
|
-
import { randomBytes } from "crypto";
|
|
332
|
-
import * as openpgp2 from "openpgp";
|
|
333
354
|
|
|
334
355
|
// src/platform/shared/stream-utils.ts
|
|
335
356
|
async function streamToUint8Array(stream) {
|
|
@@ -355,29 +376,16 @@ async function streamToUint8Array(stream) {
|
|
|
355
376
|
}
|
|
356
377
|
|
|
357
378
|
// src/platform/node.ts
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
try {
|
|
362
|
-
const eccryptoLib = await import("eccrypto");
|
|
363
|
-
eccrypto = {
|
|
364
|
-
encrypt: eccryptoLib.encrypt,
|
|
365
|
-
decrypt: eccryptoLib.decrypt,
|
|
366
|
-
getPublicCompressed: eccryptoLib.getPublicCompressed
|
|
367
|
-
};
|
|
368
|
-
} catch (error) {
|
|
369
|
-
throw new Error(`Failed to load eccrypto library: ${error}`);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return eccrypto;
|
|
373
|
-
}
|
|
379
|
+
init_lazy_import();
|
|
380
|
+
var getOpenPGP2 = lazyImport(() => import("openpgp"));
|
|
381
|
+
var getEccrypto = lazyImport(() => import("eccrypto"));
|
|
374
382
|
var NodeCryptoAdapter = class {
|
|
375
383
|
async encryptWithPublicKey(data, publicKeyHex) {
|
|
376
384
|
try {
|
|
377
|
-
const
|
|
385
|
+
const eccrypto = await getEccrypto();
|
|
378
386
|
const publicKey = Buffer.from(publicKeyHex, "hex");
|
|
379
387
|
const message = Buffer.from(data, "utf8");
|
|
380
|
-
const encrypted = await
|
|
388
|
+
const encrypted = await eccrypto.encrypt(publicKey, message);
|
|
381
389
|
const result = Buffer.concat([
|
|
382
390
|
encrypted.iv,
|
|
383
391
|
encrypted.ephemPublicKey,
|
|
@@ -391,15 +399,12 @@ var NodeCryptoAdapter = class {
|
|
|
391
399
|
}
|
|
392
400
|
async decryptWithPrivateKey(encryptedData, privateKeyHex) {
|
|
393
401
|
try {
|
|
394
|
-
const
|
|
402
|
+
const eccrypto = await getEccrypto();
|
|
395
403
|
const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);
|
|
396
404
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
397
405
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
398
406
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
399
|
-
const decrypted = await
|
|
400
|
-
privateKeyBuffer,
|
|
401
|
-
encryptedObj
|
|
402
|
-
);
|
|
407
|
+
const decrypted = await eccrypto.decrypt(privateKeyBuffer, encryptedObj);
|
|
403
408
|
return decrypted.toString("utf8");
|
|
404
409
|
} catch (error) {
|
|
405
410
|
throw new Error(`Decryption failed: ${error}`);
|
|
@@ -407,9 +412,9 @@ var NodeCryptoAdapter = class {
|
|
|
407
412
|
}
|
|
408
413
|
async generateKeyPair() {
|
|
409
414
|
try {
|
|
410
|
-
const
|
|
411
|
-
const privateKey =
|
|
412
|
-
const publicKey =
|
|
415
|
+
const eccrypto = await getEccrypto();
|
|
416
|
+
const privateKey = eccrypto.generatePrivate();
|
|
417
|
+
const publicKey = eccrypto.getPublicCompressed(privateKey);
|
|
413
418
|
return {
|
|
414
419
|
privateKey: privateKey.toString("hex"),
|
|
415
420
|
publicKey: publicKey.toString("hex")
|
|
@@ -420,9 +425,9 @@ var NodeCryptoAdapter = class {
|
|
|
420
425
|
}
|
|
421
426
|
async encryptWithWalletPublicKey(data, publicKey) {
|
|
422
427
|
try {
|
|
423
|
-
const
|
|
428
|
+
const eccrypto = await getEccrypto();
|
|
424
429
|
const uncompressedKey = processWalletPublicKey(publicKey);
|
|
425
|
-
const encrypted = await
|
|
430
|
+
const encrypted = await eccrypto.encrypt(
|
|
426
431
|
uncompressedKey,
|
|
427
432
|
Buffer.from(data)
|
|
428
433
|
);
|
|
@@ -439,12 +444,12 @@ var NodeCryptoAdapter = class {
|
|
|
439
444
|
}
|
|
440
445
|
async decryptWithWalletPrivateKey(encryptedData, privateKey) {
|
|
441
446
|
try {
|
|
442
|
-
const
|
|
447
|
+
const eccrypto = await getEccrypto();
|
|
443
448
|
const privateKeyBuffer = processWalletPrivateKey(privateKey);
|
|
444
449
|
const encryptedBuffer = Buffer.from(encryptedData, "hex");
|
|
445
450
|
const { iv, ephemPublicKey, ciphertext, mac } = parseEncryptedDataBuffer(encryptedBuffer);
|
|
446
451
|
const encryptedObj = { iv, ephemPublicKey, ciphertext, mac };
|
|
447
|
-
const decryptedBuffer = await
|
|
452
|
+
const decryptedBuffer = await eccrypto.decrypt(
|
|
448
453
|
privateKeyBuffer,
|
|
449
454
|
encryptedObj
|
|
450
455
|
);
|
|
@@ -455,10 +460,11 @@ var NodeCryptoAdapter = class {
|
|
|
455
460
|
}
|
|
456
461
|
async encryptWithPassword(data, password) {
|
|
457
462
|
try {
|
|
458
|
-
const
|
|
463
|
+
const openpgp = await getOpenPGP2();
|
|
464
|
+
const message = await openpgp.createMessage({
|
|
459
465
|
binary: data
|
|
460
466
|
});
|
|
461
|
-
const encrypted = await
|
|
467
|
+
const encrypted = await openpgp.encrypt({
|
|
462
468
|
message,
|
|
463
469
|
passwords: [password],
|
|
464
470
|
format: "binary"
|
|
@@ -478,10 +484,11 @@ var NodeCryptoAdapter = class {
|
|
|
478
484
|
}
|
|
479
485
|
async decryptWithPassword(encryptedData, password) {
|
|
480
486
|
try {
|
|
481
|
-
const
|
|
487
|
+
const openpgp = await getOpenPGP2();
|
|
488
|
+
const message = await openpgp.readMessage({
|
|
482
489
|
binaryMessage: encryptedData
|
|
483
490
|
});
|
|
484
|
-
const { data: decrypted } = await
|
|
491
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
485
492
|
message,
|
|
486
493
|
passwords: [password],
|
|
487
494
|
format: "binary"
|
|
@@ -495,12 +502,13 @@ var NodeCryptoAdapter = class {
|
|
|
495
502
|
var NodePGPAdapter = class {
|
|
496
503
|
async encrypt(data, publicKeyArmored) {
|
|
497
504
|
try {
|
|
498
|
-
const
|
|
499
|
-
const
|
|
500
|
-
|
|
505
|
+
const openpgp = await getOpenPGP2();
|
|
506
|
+
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
|
507
|
+
const encrypted = await openpgp.encrypt({
|
|
508
|
+
message: await openpgp.createMessage({ text: data }),
|
|
501
509
|
encryptionKeys: publicKey,
|
|
502
510
|
config: {
|
|
503
|
-
preferredCompressionAlgorithm:
|
|
511
|
+
preferredCompressionAlgorithm: openpgp.enums.compression.zlib
|
|
504
512
|
}
|
|
505
513
|
});
|
|
506
514
|
return encrypted;
|
|
@@ -510,13 +518,14 @@ var NodePGPAdapter = class {
|
|
|
510
518
|
}
|
|
511
519
|
async decrypt(encryptedData, privateKeyArmored) {
|
|
512
520
|
try {
|
|
513
|
-
const
|
|
521
|
+
const openpgp = await getOpenPGP2();
|
|
522
|
+
const privateKey = await openpgp.readPrivateKey({
|
|
514
523
|
armoredKey: privateKeyArmored
|
|
515
524
|
});
|
|
516
|
-
const message = await
|
|
525
|
+
const message = await openpgp.readMessage({
|
|
517
526
|
armoredMessage: encryptedData
|
|
518
527
|
});
|
|
519
|
-
const { data: decrypted } = await
|
|
528
|
+
const { data: decrypted } = await openpgp.decrypt({
|
|
520
529
|
message,
|
|
521
530
|
decryptionKeys: privateKey
|
|
522
531
|
});
|
|
@@ -527,8 +536,9 @@ var NodePGPAdapter = class {
|
|
|
527
536
|
}
|
|
528
537
|
async generateKeyPair(options) {
|
|
529
538
|
try {
|
|
539
|
+
const openpgp = await getOpenPGP2();
|
|
530
540
|
const keyGenParams = getPGPKeyGenParams(options);
|
|
531
|
-
const { privateKey, publicKey } = await
|
|
541
|
+
const { privateKey, publicKey } = await openpgp.generateKey(keyGenParams);
|
|
532
542
|
return { publicKey, privateKey };
|
|
533
543
|
} catch (error) {
|
|
534
544
|
throw wrapCryptoError("PGP key generation", error);
|