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

    Function decryptWithWalletPrivateKey

    • Decrypts data that was encrypted with the corresponding public key.

      Parameters

      • encryptedData: string

        The encrypted data string to decrypt

      • privateKey: string

        The private key corresponding to the public key used for encryption

      • platformAdapter: VanaPlatformAdapter

        The platform adapter providing cryptographic operations

      Returns Promise<string>

      Promise resolving to the decrypted data as a string

      This function performs asymmetric decryption using the recipient's private key to decrypt data that was encrypted with the corresponding public key. It's the counterpart to encryptWithWalletPublicKey and is typically used by applications or servers to decrypt data that was shared with them by users.

      The function automatically handles platform-specific cryptographic operations and provides consistent behavior across browser and Node.js environments.

      When decryption fails due to invalid key, corrupted data, or key mismatch

      // Decrypt data received from a user (server-side)
      const encryptedUserData = "encrypted_string_from_user";
      const serverPrivateKey = process.env.SERVER_PRIVATE_KEY;

      const decrypted = await decryptWithWalletPrivateKey(
      encryptedUserData,
      serverPrivateKey,
      platformAdapter
      );

      const userData = JSON.parse(decrypted);
      console.log('User data:', userData);

      // Handle decryption errors gracefully
      try {
      const result = await decryptWithWalletPrivateKey(
      encryptedData,
      privateKey,
      platformAdapter
      );
      } catch (error) {
      if (error.message.includes('invalid key')) {
      console.error('Key mismatch - data not encrypted for this recipient');
      } else {
      console.error('Decryption failed:', error.message);
      }
      }