Skip to main content

Attested Decrypt

Attested Decrypt allows you to decrypt encrypted handles and verify the decryption on-chain using Ed25519 signature verification. Use this when you need to perform on-chain logic based on decrypted values.

Import

Basic Usage

Attested Decrypt uses the same decrypt() function as Attested Reveal. The difference is that you use result.ed25519Instructions to build an on-chain verification transaction.

How It Works

  1. Send encrypted handles to the covalidator
  2. Covalidator decrypts and returns plaintexts with Ed25519 signatures
  3. Build a transaction with Ed25519 verification instructions
  4. Add your program instruction that uses the decrypted values
  5. Submit transaction - Solana verifies signatures before executing your instruction

Example: Verify Addition Result On-Chain

Example: Verify Multiple Values On-Chain

Example: Verify e_select Result On-Chain


React Integration


Getting Handles

There are two ways to get encrypted handles for decryption:

Option 1: From Transaction Logs

When your program emits handles in logs after an operation:

Option 2: From On-Chain Account (e.g., Token Balance PDA)

When the encrypted handle is stored in an account (like a confidential token balance):

Example: Verify Token Balance On-Chain


API Reference

decrypt(handles, options)

Decrypts encrypted handles and returns plaintexts with Ed25519 verification data. Parameters:
  • handles: string[] - Array of encrypted handles as decimal strings (max 10)
  • options: DecryptOptions - Wallet authentication options
Handles must be passed as decimal string representations (e.g., "123456789012345678901234567890"), not hex strings. When reading a handle from an on-chain account (stored as u128), convert it to a decimal string using .toString().
Returns: Promise<DecryptResult>

Types

DecryptOptions

The signMessage function can come from:
  • Wallet adapter (e.g., Phantom): wallet.signMessage
  • tweetnacl for testing: async (msg) => nacl.sign.detached(msg, keypair.secretKey)
For complete examples, see the lightning-rod-solana tests.

DecryptResult

Utility Functions


Error Handling

Errors

Error MessageCauseSolution
No handles provided for decryptionEmpty handles array []Pass at least one handle
Maximum 10 handles per transaction. This is a Solana transaction size limitMore than 10 handlesSplit into multiple calls of ≤10 handles
At least one handle is required for decryptionEmpty handles arrayPass at least one handle
Covalidator API request failed: <details>Covalidator errorCheck network; handle may be invalid
Covalidator returned empty plaintextMissing plaintextHandle may be invalid or not found
Covalidator signature verification failed. The response may be tamperedEd25519 verification failedResponse integrity compromised
Failed to build attested decrypt transactionTransaction construction failedCheck handles and instruction builder
Transaction failed: <details>On-chain execution failedCheck Solana explorer for details
Failed to create Ed25519 verification instruction: <details>Ed25519 instruction failedSignature format may be invalid
Attested decryption failed: <details>General failureCheck error details

When to Use Attested Decrypt vs Attested Reveal

Use CaseUse
Conditional on-chain logic based on decrypted valueAttested Decrypt
Verify decryption proof on-chainAttested Decrypt
Display balance in UIAttested Reveal
Show transaction result to userAttested Reveal