Vana SDK - v2.2.2
    Preparing search index...

    Function encryptWithWalletPublicKey

    • Encrypts data using a wallet's public key for secure sharing with specific recipients.

      Parameters

      • data: string | Blob

        The data to encrypt (string or Blob)

      • publicKey: string

        The recipient's public key in hexadecimal format

      • platformAdapter: VanaPlatformAdapter

        The platform adapter providing cryptographic operations

      Returns Promise<string>

      Promise resolving to the encrypted data as a string

      This function implements asymmetric encryption using the recipient's public key, enabling secure data sharing where only the holder of the corresponding private key can decrypt the data. It automatically handles different data types and uses platform-appropriate cryptographic libraries for maximum compatibility.

      This is commonly used when granting permissions to applications or servers, where the data needs to be encrypted for a specific recipient's public key.

      When encryption fails due to invalid key or data format

      // Encrypt data for a specific application's public key
      const appPublicKey = "0x04a1b2c3..."; // Application's public key
      const sensitiveData = "User's private information";

      const encrypted = await encryptWithWalletPublicKey(
      sensitiveData,
      appPublicKey,
      platformAdapter
      );

      console.log('Encrypted for app:', encrypted);

      // Encrypt file data for server processing
      const fileBlob = new File(['{"name":"John","age":30}'], 'profile.json');
      const encryptedFile = await encryptWithWalletPublicKey(
      fileBlob,
      serverPublicKey,
      platformAdapter
      );