{"version":3,"sources":["../../src/platform/node.ts"],"sourcesContent":["/**\n * Provides Node.js-specific implementations of platform abstraction interfaces.\n *\n * @remarks\n * This module implements all platform-specific operations for Node.js environments,\n * including cryptography, PGP operations, HTTP requests, and caching. It dynamically\n * imports dependencies to avoid Turbopack TDZ issues and uses a custom ECIES\n * implementation with native secp256k1 for optimal performance.\n *\n * WARNING: Dependencies that access globals during init MUST be dynamically imported\n * to support Turbopack. See: https://github.com/vercel/next.js/issues/82632\n *\n * @example\n * ```typescript\n * // Use the Node.js platform adapter\n * import { nodePlatformAdapter} from '@vana-sdk/platform/node';\n *\n * // Encrypt data with public key\n * const encrypted = await nodePlatformAdapter.crypto.encryptWithPublicKey(\n *   'sensitive data',\n *   '0x04...' // Public key hex\n * );\n *\n * // Generate PGP key pair\n * const { publicKey, privateKey } = await nodePlatformAdapter.pgp.generateKeyPair({\n *   name: 'Data Owner',\n *   email: 'owner@example.com'\n * });\n * ```\n *\n * @category Platform\n * @module platform/node\n */\n\nimport type {\n  VanaPlatformAdapter,\n  VanaCryptoAdapter,\n  VanaPGPAdapter,\n  VanaHttpAdapter,\n  VanaCacheAdapter,\n} from \"./interface\";\nimport { getPGPKeyGenParams } from \"./shared/pgp-utils\";\nimport { wrapCryptoError } from \"./shared/error-utils\";\nimport { streamToUint8Array } from \"./shared/stream-utils\";\nimport { lazyImport } from \"../utils/lazy-import\";\nimport { WalletKeyEncryptionService } from \"../crypto/services/WalletKeyEncryptionService\";\nimport {\n  processWalletPrivateKey,\n  parseEncryptedDataBuffer,\n  processWalletPublicKey,\n} from \"../utils/crypto-utils\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\n\n// Import ECIES implementation\nimport { NodeECIESUint8Provider } from \"../crypto/ecies/node\";\nimport { ECIESError } from \"../crypto/ecies/interface\";\nimport type { ECIESEncrypted } from \"../crypto/ecies\";\nimport { randomBytes } from \"crypto\";\nimport secp256k1Import from \"secp256k1\";\n\n// Type definition for secp256k1 module\ninterface Secp256k1Module {\n  privateKeyVerify(privateKey: Buffer): boolean;\n  publicKeyCreate(privateKey: Buffer, compressed: boolean): Buffer;\n  publicKeyVerify(publicKey: Buffer): boolean;\n  publicKeyConvert(publicKey: Buffer, compressed: boolean): Buffer;\n  ecdh(\n    publicKey: Buffer,\n    privateKey: Buffer,\n    options: {\n      hashfn: (x: Uint8Array, y: Uint8Array, output?: Uint8Array) => Uint8Array;\n    },\n    output: Buffer,\n  ): Buffer;\n}\n\n/**\n * Implements cryptographic operations for Node.js environments.\n *\n * @remarks\n * Provides ECIES encryption/decryption, key generation, and password-based\n * encryption using a custom ECIES implementation with native secp256k1.\n *\n * @internal\n */\nclass NodeCryptoAdapter implements VanaCryptoAdapter {\n  private eciesProvider = new NodeECIESUint8Provider();\n  private walletService = new WalletKeyEncryptionService({\n    eciesProvider: this.eciesProvider,\n  });\n\n  /**\n   * Encrypts data using ECIES with a public key.\n   *\n   * @param data - The plaintext string to encrypt.\n   *   Typically user data or sensitive information.\n   * @param publicKeyHex - The recipient's public key in hex format.\n   *   Obtain from key generation or user profile.\n   * @returns Encrypted data as a hex string containing IV, ephemeral key, ciphertext, and MAC\n   *\n   * @throws {Error} If encryption fails or public key is invalid\n   */\n  async encryptWithPublicKey(\n    data: string,\n    publicKeyHex: string,\n  ): Promise<string> {\n    try {\n      // Process public key to handle 0x prefix and convert to Buffer\n      const publicKeyBytes = processWalletPublicKey(publicKeyHex);\n      const publicKey = Buffer.from(publicKeyBytes);\n      const message = Buffer.from(data, \"utf8\");\n\n      const encrypted = await this.eciesProvider.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      if (error instanceof ECIESError) {\n        throw error;\n      }\n      throw new Error(\n        `Encryption failed: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  /**\n   * Decrypts ECIES-encrypted data using a private key.\n   *\n   * @param encryptedData - Hex string containing encrypted data.\n   *   Must include IV, ephemeral public key, ciphertext, and MAC.\n   * @param privateKeyHex - The private key in hex format.\n   *   Must correspond to the public key used for encryption.\n   * @returns The decrypted plaintext string\n   *\n   * @throws {Error} If decryption fails or MAC verification fails\n   * @throws {ECIESError} If using custom ECIES and specific error occurs\n   */\n  async decryptWithPrivateKey(\n    encryptedData: string,\n    privateKeyHex: string,\n  ): Promise<string> {\n    try {\n      const privateKeyBuffer = processWalletPrivateKey(privateKeyHex);\n      // Handle 0x prefix in encrypted data (e.g., from viem's toHex)\n      const encryptedHex = encryptedData.startsWith(\"0x\")\n        ? encryptedData.slice(2)\n        : encryptedData;\n      const encryptedBuffer = Buffer.from(encryptedHex, \"hex\");\n      const { iv, ephemPublicKey, ciphertext, mac } =\n        parseEncryptedDataBuffer(encryptedBuffer);\n\n      // Reconstruct the encrypted data structure\n      const encryptedObj: ECIESEncrypted = {\n        iv,\n        ephemPublicKey,\n        ciphertext,\n        mac,\n      };\n\n      const decrypted = await this.eciesProvider.decrypt(\n        privateKeyBuffer,\n        encryptedObj,\n      );\n      return new TextDecoder().decode(decrypted);\n    } catch (error) {\n      if (error instanceof ECIESError) {\n        throw error;\n      }\n      throw new Error(\n        `Decryption failed: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  /**\n   * Generates a new secp256k1 key pair for ECIES operations.\n   *\n   * @returns Object containing hex-encoded public and private keys\n   * @returns returns.publicKey - Compressed public key in hex format\n   * @returns returns.privateKey - Private key in hex format\n   *\n   * @throws {Error} If key generation fails\n   */\n  async generateKeyPair(): Promise<{ publicKey: string; privateKey: string }> {\n    try {\n      const secp256k1 = secp256k1Import as unknown as Secp256k1Module;\n\n      // Generate private key\n      let privateKey: Buffer;\n      do {\n        privateKey = randomBytes(32);\n      } while (!secp256k1.privateKeyVerify(privateKey));\n\n      // Get compressed public key\n      const publicKey = Buffer.from(\n        secp256k1.publicKeyCreate(privateKey, true),\n      );\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  /**\n   * Encrypts data using a wallet's public key.\n   *\n   * @param data - The plaintext string to encrypt.\n   *   Typically permission data or DLP metadata.\n   * @param publicKey - The wallet's public key (with or without 0x prefix).\n   *   Obtain from wallet connection or user profile.\n   * @returns Encrypted data as a hex string\n   *\n   * @throws {Error} If encryption fails or key processing fails\n   */\n  async encryptWithWalletPublicKey(\n    data: string,\n    publicKey: string,\n  ): Promise<string> {\n    try {\n      return await this.walletService.encryptWithWalletPublicKey(\n        data,\n        publicKey,\n      );\n    } catch (error) {\n      throw wrapCryptoError(\"encrypt with wallet public key\", error);\n    }\n  }\n\n  /**\n   * Decrypts data using a wallet's private key.\n   *\n   * @param encryptedData - Hex string containing encrypted data.\n   *   Must be encrypted with corresponding wallet public key.\n   * @param privateKey - The wallet's private key.\n   *   Obtain from wallet connection (handle with care).\n   * @returns The decrypted plaintext string\n   *\n   * @throws {Error} If decryption fails or key is invalid\n   */\n  async decryptWithWalletPrivateKey(\n    encryptedData: string,\n    privateKey: string,\n  ): Promise<string> {\n    try {\n      return await this.walletService.decryptWithWalletPrivateKey(\n        encryptedData,\n        privateKey,\n      );\n    } catch (error) {\n      throw wrapCryptoError(\"decrypt with wallet private key\", error);\n    }\n  }\n\n  /**\n   * Encrypts binary data using password-based encryption.\n   *\n   * @param data - Binary data to encrypt.\n   *   Typically file contents or serialized objects.\n   * @param password - Password for encryption.\n   *   Often derived from wallet signatures.\n   * @returns Encrypted data as Uint8Array\n   *\n   * @remarks\n   * Uses OpenPGP for password-based encryption. Note that this is not\n   * deterministic due to OpenPGP's random salt generation.\n   *\n   * @throws {Error} If encryption fails\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  /**\n   * Decrypts password-encrypted binary data.\n   *\n   * @param encryptedData - Password-encrypted data as Uint8Array.\n   *   Must be encrypted with the same password.\n   * @param password - Password for decryption.\n   *   Must match the encryption password.\n   * @returns Decrypted data as Uint8Array\n   *\n   * @throws {Error} If decryption fails or password is incorrect\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 * Implements PGP operations for Node.js environments.\n *\n * @remarks\n * Provides PGP encryption, decryption, and key generation using the OpenPGP.js\n * library with Node.js-specific optimizations like zlib compression.\n *\n * @internal\n */\nclass NodePGPAdapter implements VanaPGPAdapter {\n  /**\n   * Encrypts data using PGP public key encryption.\n   *\n   * @param data - The plaintext string to encrypt.\n   *   Typically messages or structured data.\n   * @param publicKeyArmored - ASCII-armored PGP public key.\n   *   Obtain from PGP key generation or key servers.\n   * @returns ASCII-armored encrypted message\n   *\n   * @throws {Error} If encryption fails or public key is invalid\n   */\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  /**\n   * Decrypts PGP-encrypted data using a private key.\n   *\n   * @param encryptedData - ASCII-armored encrypted message.\n   *   Must be encrypted with corresponding public key.\n   * @param privateKeyArmored - ASCII-armored PGP private key.\n   *   Must correspond to the public key used for encryption.\n   * @returns The decrypted plaintext string\n   *\n   * @throws {Error} If decryption fails or private key is invalid\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  /**\n   * Generates a new PGP key pair.\n   *\n   * @param options - Key generation options\n   * @param options.name - Name for the key identity.\n   *   Defaults to 'Vana User'.\n   * @param options.email - Email for the key identity.\n   *   Defaults to 'user@vana.com'.\n   * @param options.passphrase - Passphrase to protect the private key.\n   *   If not provided, key is unprotected.\n   * @returns ASCII-armored public and private keys\n   *\n   * @throws {Error} If key generation fails\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 * Implements HTTP operations for Node.js environments.\n *\n * @remarks\n * Provides fetch functionality using the global fetch if available,\n * suitable for Node.js 18+ or environments with fetch polyfills.\n *\n * @internal\n */\nclass NodeHttpAdapter implements VanaHttpAdapter {\n  /**\n   * Performs an HTTP request using fetch.\n   *\n   * @param url - The URL to fetch.\n   *   Must be a valid HTTP/HTTPS URL.\n   * @param options - Standard fetch options.\n   *   See MDN fetch documentation for details.\n   * @returns Standard fetch Response object\n   *\n   * @throws {Error} If fetch is not available in the environment\n   */\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 * Implements in-memory caching for Node.js environments.\n *\n * @remarks\n * Provides a simple TTL-based cache using a Map. Cached values expire\n * after 2 hours by default. This cache is not persistent and will be\n * cleared when the process exits.\n *\n * @internal\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  /**\n   * Retrieves a cached value by key.\n   *\n   * @param key - The cache key to look up.\n   *   Typically derived from operation parameters.\n   * @returns The cached value or null if not found/expired\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  /**\n   * Stores a value in the cache with TTL.\n   *\n   * @param key - The cache key.\n   *   Should be unique per operation.\n   * @param value - The value to cache.\n   *   Typically serialized data or signatures.\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  /**\n   * Removes a specific key from the cache.\n   *\n   * @param key - The cache key to remove.\n   *   Use when cached data becomes invalid.\n   */\n  delete(key: string): void {\n    this.cache.delete(key);\n  }\n\n  /**\n   * Clears all cached values.\n   *\n   * @remarks\n   * Use with caution as this removes all cached signatures\n   * and other performance optimizations.\n   */\n  clear(): void {\n    this.cache.clear();\n  }\n}\n\n/**\n * Provides complete platform abstraction for Node.js environments.\n *\n * @remarks\n * This adapter aggregates all Node.js-specific implementations of platform\n * operations using a custom ECIES implementation with native secp256k1 for\n * optimal performance and provides consistent APIs across all operations.\n *\n * @example\n * ```typescript\n * // Create a custom Node.js adapter instance\n * const adapter = new NodePlatformAdapter();\n *\n * // Use for encryption\n * const encrypted = await adapter.crypto.encryptWithPublicKey(\n *   'secret data',\n *   publicKeyHex\n * );\n *\n * // Use for caching\n * adapter.cache.set('signature_key', signatureValue);\n * ```\n *\n * @category Platform\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 * Pre-configured Node.js platform adapter instance.\n *\n * @remarks\n * This singleton instance is the default adapter used by the SDK when\n * running in Node.js environments. It's automatically selected based on\n * platform detection.\n *\n * @example\n * ```typescript\n * import { nodePlatformAdapter } from '@vana-sdk/platform/node';\n *\n * // Use directly for platform operations\n * const keys = await nodePlatformAdapter.crypto.generateKey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