Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Verifying Decrypt Results

When you use decryptForTx, the Threshold Network returns:

  • the plaintext (decryptedValue), and
  • a signature (signature) that your contract can later verify on-chain.

If you ever receive a decrypt result from somewhere else (e.g. your backend, a cache, or another client), you can validate that the (ctHash, plaintext, signature) triple is authentic using client.verifyDecryptResult(...).

What “verify” means

verifyDecryptResult(ctHash, plaintext, signature) checks that:

  • the signature is a valid Threshold Network signature for the given ctHash (handle) and plaintext, and
  • the signature matches the expected Threshold Network signer set for that chain.

In other words: it makes sure you’re not about to submit (ctHash, plaintext, signature) where the signature is malformed, tampered with, or produced by the wrong signer.

The “signer is correct” part refers to the Threshold Network’s signing key (a distributed key controlled by the Threshold Network committee), not your wallet address. A true result means the chain’s verifier considers this signature a valid attestation from that Threshold Network key for the specific (ctHash, plaintext) pair.

Under the hood, the SDK:

  • does an eth_call to read the expected decryptResultSigner from the chain’s TaskManager (no gas), then
  • performs the signature check locally via ecrecover-equivalent recovery against keccak256(abi.encodePacked(ctHash, plaintext)).

This means your (ctHash, plaintext, signature) is not sent to the RPC node for verification.

When to use it

Use verifyDecryptResult when you want to validate decrypt results that didn’t come directly from your own decryptForTx call, for example:

  • when you received a decrypt result from an untrusted off-chain source (e.g. a backend, cache, or another client),
  • when debugging mismatches between what you decrypted and what your contract expects.

Example

// `client` must be connected (see the SDK client page)
// `decryptResult` came from an untrusted off-chain source (e.g. backend/cache/another client)
 
const isValid = await client.verifyDecryptResult(
  decryptResult.ctHash,
  decryptResult.decryptedValue,
  decryptResult.signature
);
if (!isValid) throw new Error('Rejecting untrusted decrypt result');
 
// Safe to trust that (ctHash, plaintext, signature) is authentic

Common gotchas

  • Wrong chain: verification must be performed against the same chain that produced the handle (ctHash).
  • Wrong plaintext: even a single-bit change in plaintext will make verification return false.
  • Signature formatting: the signature must be a 0x... hex string exactly as returned by decryptForTx.