UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

1 lines 22.9 kB
{"version":3,"sources":["../../src/platform/browser.ts"],"sourcesContent":["/**\n * Provides browser-specific implementations of platform abstraction interfaces.\n *\n * @remarks\n * This module implements all platform-specific operations for browser environments,\n * using native Web APIs and browser-compatible libraries. It avoids Node.js-specific\n * dependencies like Buffer, using Uint8Array and viem utilities instead. Uses a\n * custom ECIES implementation with @noble/secp256k1 for pure JavaScript crypto.\n *\n * @example\n * ```typescript\n * // Use the browser platform adapter\n * import { BrowserPlatformAdapter } from '@vana-sdk/platform/browser';\n *\n * const adapter = new BrowserPlatformAdapter();\n *\n * // Encrypt data with public key\n * const encrypted = await adapter.crypto.encryptWithPublicKey(\n * 'sensitive data',\n * '0x04...' // Public key hex\n * );\n *\n * // Use sessionStorage-backed cache\n * adapter.cache.set('temp_key', 'cached_value');\n * ```\n *\n * @category Platform\n * @module platform/browser\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 { lazyImport } from \"../utils/lazy-import\";\nimport { WalletKeyEncryptionService } from \"../crypto/services/WalletKeyEncryptionService\";\nimport { parseEncryptedDataBuffer } from \"../utils/crypto-utils\";\nimport { toHex, fromHex, stringToBytes, bytesToString, concat } from \"viem\";\nimport * as secp256k1 from \"@noble/secp256k1\";\n\n// Import browser ECIES provider\nimport { BrowserECIESUint8Provider } from \"../crypto/ecies/browser\";\n\n// Lazy-loaded dependencies to avoid Turbopack TDZ issues\nconst getOpenPGP = lazyImport(() => import(\"openpgp\"));\n\n/**\n * Implements cryptographic operations for browser environments.\n *\n * @remarks\n * Provides ECIES encryption/decryption, key generation, and password-based\n * encryption using a custom ECIES implementation with @noble/secp256k1.\n * Uses Uint8Array and viem utilities for browser compatibility.\n *\n * @internal\n */\nclass BrowserCryptoAdapter implements VanaCryptoAdapter {\n private eciesProvider = new BrowserECIESUint8Provider();\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 * Can include or omit the '0x' prefix.\n * @returns Encrypted data as a hex string without '0x' prefix\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 const prefixedHex = publicKeyHex.startsWith(\"0x\")\n ? publicKeyHex\n : `0x${publicKeyHex}`;\n const publicKeyBytes = fromHex(prefixedHex as `0x${string}`, \"bytes\");\n\n // Encrypt data using ECIES\n const encrypted = await this.eciesProvider.encrypt(\n publicKeyBytes,\n stringToBytes(data),\n );\n\n // Concatenate all components and return as hex string\n const result = concat([\n encrypted.iv,\n encrypted.ephemPublicKey,\n encrypted.ciphertext,\n encrypted.mac,\n ]);\n\n return toHex(result).slice(2); // Remove '0x' prefix for backward compatibility\n } catch (error) {\n throw wrapCryptoError(\"encryptWithPublicKey\", error);\n }\n }\n\n /**\n * Decrypts ECIES-encrypted data using a private key.\n *\n * @param encryptedData - Hex string containing encrypted data.\n * Can include or omit the '0x' prefix.\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 */\n async decryptWithPrivateKey(\n encryptedData: string,\n privateKeyHex: string,\n ): Promise<string> {\n try {\n const encryptedHex = encryptedData.startsWith(\"0x\")\n ? encryptedData\n : `0x${encryptedData}`;\n const privateHex = privateKeyHex.startsWith(\"0x\")\n ? privateKeyHex\n : `0x${privateKeyHex}`;\n const encryptedBytes = fromHex(encryptedHex as `0x${string}`, \"bytes\");\n const privateKeyBytes = fromHex(privateHex as `0x${string}`, \"bytes\");\n\n // Parse the encrypted data into components\n const encrypted = parseEncryptedDataBuffer(encryptedBytes);\n\n // Decrypt using ECIES\n const decrypted = await this.eciesProvider.decrypt(\n privateKeyBytes,\n encrypted,\n );\n\n return bytesToString(decrypted);\n } catch (error) {\n throw wrapCryptoError(\"decryptWithPrivateKey\", 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.\n * Automatically handles compressed/uncompressed formats.\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(\"encryptWithWalletPublicKey\", 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(\"decryptWithWalletPrivateKey\", error);\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.privateKey - Private key in hex format without '0x'\n * @returns returns.publicKey - Compressed public key in hex format without '0x'\n *\n * @throws {Error} If key generation fails\n */\n async generateKeyPair(): Promise<{\n privateKey: string;\n publicKey: string;\n }> {\n try {\n // Generate random private key\n const privateKeyBytes = secp256k1.utils.randomPrivateKey();\n\n // Generate public key (compressed for consistency with Node implementation)\n const publicKeyBytes = secp256k1.getPublicKey(privateKeyBytes, true);\n\n return {\n privateKey: toHex(privateKeyBytes).slice(2),\n publicKey: toHex(publicKeyBytes).slice(2),\n };\n } catch (error) {\n throw wrapCryptoError(\"generateKeyPair\", 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 with automatic\n * salt generation for security.\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\n // Create a message from the data\n const message = await openpgp.createMessage({ binary: data });\n\n // Encrypt with password\n const encrypted = await openpgp.encrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n return new Uint8Array(encrypted as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"encryptWithPassword\", 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\n // Read the encrypted message\n const message = await openpgp.readMessage({\n binaryMessage: encryptedData,\n });\n\n // Decrypt with password\n const { data } = await openpgp.decrypt({\n message,\n passwords: [password],\n format: \"binary\",\n });\n\n return new Uint8Array(data as ArrayBuffer);\n } catch (error) {\n throw wrapCryptoError(\"decryptWithPassword\", error);\n }\n }\n}\n\n/**\n * Implements PGP operations for browser environments.\n *\n * @remarks\n * Provides PGP encryption, decryption, and key generation using the OpenPGP.js\n * library with browser-optimized configuration.\n *\n * @internal\n */\nclass BrowserPGPAdapter 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 new Error(`PGP encryption failed: ${String(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 new Error(`PGP decryption failed: ${String(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 browser environments.\n *\n * @remarks\n * Uses the native Fetch API available in all modern browsers.\n *\n * @internal\n */\nclass BrowserHttpAdapter implements VanaHttpAdapter {\n /**\n * Performs an HTTP request using the Fetch API.\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 async fetch(url: string, options?: RequestInit): Promise<Response> {\n return fetch(url, options);\n }\n}\n\n/**\n * Implements secure caching for browser environments.\n *\n * @remarks\n * Uses sessionStorage for temporary caching that's automatically cleared\n * when the browser tab closes. This provides better security for sensitive\n * data like signatures compared to localStorage. All keys are prefixed to\n * avoid conflicts with other applications.\n *\n * @internal\n */\nclass BrowserCacheAdapter implements VanaCacheAdapter {\n private readonly prefix = \"vana_cache_\";\n\n /**\n * Retrieves a cached value by key.\n *\n * @param key - The cache key to look up.\n * Automatically prefixed to avoid conflicts.\n * @returns The cached value or null if not found\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 /**\n * Stores a value in sessionStorage.\n *\n * @param key - The cache key.\n * Automatically prefixed with 'vana_cache_'.\n * @param value - The value to cache.\n * Will be cleared when tab closes.\n */\n set(key: string, value: string): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n sessionStorage.setItem(this.prefix + key, value);\n } catch {\n // Ignore storage errors (quota exceeded, etc.)\n }\n }\n\n /**\n * Removes a specific key from the cache.\n *\n * @param key - The cache key to remove.\n * Only removes the prefixed key.\n */\n delete(key: string): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n sessionStorage.removeItem(this.prefix + key);\n } catch {\n // Ignore storage errors\n }\n }\n\n /**\n * Clears all Vana-prefixed cache entries.\n *\n * @remarks\n * Only removes entries with the 'vana_cache_' prefix,\n * preserving other sessionStorage data.\n */\n clear(): void {\n try {\n if (typeof sessionStorage === \"undefined\") {\n return;\n }\n // Only clear our prefixed keys to avoid affecting other data\n const keysToRemove: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n if (key?.startsWith(this.prefix)) {\n keysToRemove.push(key);\n }\n }\n keysToRemove.forEach((key) => {\n sessionStorage.removeItem(key);\n });\n } catch {\n // Ignore storage errors\n }\n }\n}\n\n/**\n * Provides complete platform abstraction for browser environments.\n *\n * @remarks\n * This adapter aggregates all browser-specific implementations of platform\n * operations. It uses native Web APIs where possible and browser-compatible\n * libraries for crypto and PGP operations using a custom ECIES implementation\n * with @noble/secp256k1 for pure JavaScript cryptography.\n *\n * @example\n * ```typescript\n * // Create a browser adapter instance\n * const adapter = new BrowserPlatformAdapter();\n *\n * // All platform operations are available\n * const encrypted = await adapter.crypto.encryptWithPublicKey(\n * 'secret',\n * publicKey\n * );\n *\n * const response = await adapter.http.fetch('/api/data');\n *\n * adapter.cache.set('key', 'value'); // Uses sessionStorage\n * ```\n *\n * @category Platform\n */\nexport class BrowserPlatformAdapter implements VanaPlatformAdapter {\n public readonly crypto = new BrowserCryptoAdapter();\n public readonly pgp = new BrowserPGPAdapter();\n public readonly http = new BrowserHttpAdapter();\n public readonly cache = new BrowserCacheAdapter();\n public readonly platform = \"browser\" as const;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqCA,uBAAmC;AACnC,yBAAgC;AAChC,yBAA2B;AAC3B,wCAA2C;AAC3C,0BAAyC;AACzC,kBAAqE;AACrE,gBAA2B;AAG3B,qBAA0C;AAG1C,MAAM,iBAAa,+BAAW,MAAM,OAAO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