UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

89 lines (88 loc) 3.36 kB
/** * Service for wallet key encryption and decryption operations. * * @remarks * This service separates business logic (wallet key processing) from crypto primitives * (ECIES operations). It handles key normalization, data conversion, and format transformation * while delegating actual cryptographic operations to the provided ECIES provider. * * @category Cryptography * @internal */ import type { ECIESProvider, ECIESEncrypted } from "../ecies/interface"; export interface WalletKeyEncryptionServiceConfig { /** ECIES provider for encryption/decryption */ eciesProvider: ECIESProvider; } /** * Service for wallet key encryption and decryption operations * * @remarks * This service encapsulates the business logic for wallet key operations, * delegating actual cryptographic operations to the provided ECIES provider. * It handles key normalization, data conversion, and format transformation. * * @internal */ export declare class WalletKeyEncryptionService { private readonly eciesProvider; constructor(config: WalletKeyEncryptionServiceConfig); /** * Encrypts data using a wallet's public key. * * @param data - The plaintext message to encrypt for the wallet owner. * @param publicKey - The recipient wallet's public key for encryption. * @returns A promise that resolves to the encrypted data as a hex string. * @throws {Error} When encryption fails due to invalid key format. * * @example * ```typescript * const encrypted = await processor.encryptWithWalletPublicKey( * "Secret message", * "0x04..." // 65-byte uncompressed public key * ); * console.log(`Encrypted: ${encrypted}`); * ``` */ encryptWithWalletPublicKey(data: string, publicKey: string | Uint8Array): Promise<string>; /** * Decrypts data using a wallet's private key. * * @param encryptedData - The hex-encoded encrypted data to decrypt. * @param privateKey - The wallet's private key for decryption. * @returns A promise that resolves to the decrypted plaintext message. * @throws {Error} When decryption fails due to invalid data or key format. * * @example * ```typescript * const decrypted = await processor.decryptWithWalletPrivateKey( * encryptedHexString, * "0x..." // 32-byte private key * ); * console.log(`Decrypted: ${decrypted}`); * ``` */ decryptWithWalletPrivateKey(encryptedData: string, privateKey: string | Uint8Array): Promise<string>; /** * Encrypts a Uint8Array with a wallet public key * * @param data - Binary data to encrypt * @param publicKey - Public key as hex string or Uint8Array * @returns Encrypted data structure */ encryptBinary(data: Uint8Array, publicKey: string | Uint8Array): Promise<ECIESEncrypted>; /** * Decrypts to a Uint8Array with a wallet private key * * @param encrypted - Encrypted data structure * @param privateKey - Private key as hex string or Uint8Array * @returns Decrypted binary data */ decryptBinary(encrypted: ECIESEncrypted, privateKey: string | Uint8Array): Promise<Uint8Array>; /** * Gets the underlying ECIES provider * * @returns The ECIES provider instance */ getECIESProvider(): ECIESProvider; }