UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

87 lines (86 loc) 2.73 kB
/** * Provides Node.js-specific implementations of platform abstraction interfaces. * * @remarks * This module implements all platform-specific operations for Node.js environments, * including cryptography, PGP operations, HTTP requests, and caching. It dynamically * imports dependencies to avoid Turbopack TDZ issues and uses a custom ECIES * implementation with native secp256k1 for optimal performance. * * WARNING: Dependencies that access globals during init MUST be dynamically imported * to support Turbopack. See: https://github.com/vercel/next.js/issues/82632 * * @example * ```typescript * // Use the Node.js platform adapter * import { nodePlatformAdapter} from '@vana-sdk/platform/node'; * * // Encrypt data with public key * const encrypted = await nodePlatformAdapter.crypto.encryptWithPublicKey( * 'sensitive data', * '0x04...' // Public key hex * ); * * // Generate PGP key pair * const { publicKey, privateKey } = await nodePlatformAdapter.pgp.generateKeyPair({ * name: 'Data Owner', * email: 'owner@example.com' * }); * ``` * * @category Platform * @module platform/node */ import type { VanaPlatformAdapter, VanaCryptoAdapter, VanaPGPAdapter, VanaHttpAdapter, VanaCacheAdapter } from "./interface"; /** * Provides complete platform abstraction for Node.js environments. * * @remarks * This adapter aggregates all Node.js-specific implementations of platform * operations using a custom ECIES implementation with native secp256k1 for * optimal performance and provides consistent APIs across all operations. * * @example * ```typescript * // Create a custom Node.js adapter instance * const adapter = new NodePlatformAdapter(); * * // Use for encryption * const encrypted = await adapter.crypto.encryptWithPublicKey( * 'secret data', * publicKeyHex * ); * * // Use for caching * adapter.cache.set('signature_key', signatureValue); * ``` * * @category Platform */ export declare class NodePlatformAdapter implements VanaPlatformAdapter { crypto: VanaCryptoAdapter; pgp: VanaPGPAdapter; http: VanaHttpAdapter; cache: VanaCacheAdapter; platform: "node"; constructor(); } /** * Pre-configured Node.js platform adapter instance. * * @remarks * This singleton instance is the default adapter used by the SDK when * running in Node.js environments. It's automatically selected based on * platform detection. * * @example * ```typescript * import { nodePlatformAdapter } from '@vana-sdk/platform/node'; * * // Use directly for platform operations * const keys = await nodePlatformAdapter.crypto.generateKeyPair(); * ``` * * @category Platform */ export declare const nodePlatformAdapter: VanaPlatformAdapter;