# Provably encrypting to Human Network, and setting custom decryption conditions.

For provable encryption, the user can interact with Human Network via the DecryptBabyJubJub method. This works via ElGamal decryption. ElGamal decryption only requires a scalar multiplication from the network, so it is compatible with the Human Network architecture.&#x20;

## How ElGamal encryption works

When Alice wants to encrypt message *M* represented as a point to Bob's public key *B,* she generates an ephemeral (private, public) keypair:

$$
(a, A = a \* G)
$$

where *G* is the curve's generator.&#x20;

The encrypted ciphertext is

$$
(A, aB+M)
$$

To decrypt, Bob can perform Diffie Hellman to find the shared secret *aB*

$$
aB = bA
$$

since Bob knows his own secret *b* and now knows *A* from the ciphertext

and decrypt the message from the ciphertext:

$$
M = aB + M - bA
$$

## Decentralizing Bob with Human Network

Notice the only operation Bob had to do with his secret key was a *scalar multiplication* by Alice's ephemeral public key. Because it's scalar multiplication, it can be done in a decentralized way with Human network.

The final step of recovering *M* by subtracting *bA* does not have to be done by Human Network. In fact, there is more privacy if Human network never sees *M*.

As a result, ciphertext itself is never touched by Human Network. It can be stored on a blockchain or, for GDPR protection and security, by an Observer node. Human Network simply computes *bA* and never decrypts the message -- the ciphertext is needed to decrypt the actual message. This makes Human Network simpler and more secure: even if the secret key of Human Network were to be compromised, nobody can learn the message without also learning the ciphertext.

Now, the only question is:

> &#x20;*How does Human Network know when it should assist in decryption? It would not protect user privacy if it were to help decrypt **all** data anyone ever asks it to help decrypt.*

## Limiting Decryption

Human network limits decryption rights by adding programmable privacy: When Alice encrypts a message, she also uses her ephemeral private key *a* to sign the address of an Ethereum contract. This contract should have the following ABI:

```
function decryptionCredits(address decryptor) external view returns (uint)
```

`decryptionCredits` says how many times a particular `decryptor` is allowed to decrypt. You may expect this contract `bool` makes more sense, but returning a `uint` enables simple implementation of other potentially common cases. E.g. limiting an allowlisted decryptor to a certain number of decryptions per day.&#x20;

Human Network will perform scalar multiplication (returning *bA*) if *A* has signed a smart contract where the decryptor is has made fewer requests than the minimum of&#x20;

* Decryption credits returned by the smart contract&#x20;
* Human credits purchased

*So how do we actually use this? See*&#x20;

{% content-ref url="/pages/MaMtzcLiEDACMNjTvAKu" %}
[Decrypting Provably Encrypted Data Over BabyJubJub Curve](/for-developers/decrypting-provably-encrypted-data-over-babyjubjub-curve.md)
{% endcontent-ref %}

## Decryption Sequence Diagram

<figure><img src="/files/rLMFRZXrOIg48LZhSZZF" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.network.human.tech/overview/methods-and-their-use-cases/provably-encrypting-to-human-network-and-setting-custom-decryption-conditions..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
