# ClientNode Class

The `ClientNode` class represents a client that interacts with the CoFHE (Collaborative Fully Homomorphic Encryption) library to perform computations using on OpenVector network. It provides methods to send computation requests, handle responses, and access cryptographic functionalities.

### Public Member Functions

#### `void compute(ComputeRequest request, ComputeResponse **response);`

Performs a computation using the CoFHE network based on the provided `ComputeRequest`. The result is stored in the `ComputeResponse` object.

```cpp
ComputeRequest request = /* ... */;
ComputeResponse* response = nullptr;

clientNode.compute(request, &response);

// Use the response
if (response->status() == ComputeResponse::Status::OK) {
    // Process the result
}
```

* **Parameters:**
  * `request`: A `ComputeRequest` object containing the computation details and input data.
  * `response`: A double pointer to a `ComputeResponse` object where the result will be stored.
* **Usage Notes:**
  * Ensure that the `response` pointer is initialized to `nullptr` before passing it to the function.
  * After the computation, check the status of the `response` to determine if the computation was successful.

#### `CryptoSystem& crypto_system();`

Returns a reference to the `CryptoSystem` object used by the client node. This object can be used to perform cryptographic operations such as encryption, decryption, and homomorphic arithmetic that are supported locally.

```cpp
CryptoSystem& cs = clientNode.crypto_system();
```

* **Usage Notes:**
  * Use this function when you need to perform cryptographic operations without involving the network.
  * The returned `CryptoSystem` provides methods as defined in the CryptoSystem Interface.

#### `const CryptoSystem& crypto_system() const;`

Const version of `crypto_system()`. Returns a constant reference to the `CryptoSystem` object.

```cpp
const CryptoSystem& cs = clientNode.crypto_system();
```

#### `typename CryptoSystem::PublicKey& network_public_key();`

Returns a reference to the public key of the network. This key is used to encrypt data that will be sent to the network for computation.

```cpp
auto& networkPk = clientNode.network_public_key();
```

* **Usage Notes:**
  * Use this public key to encrypt your data before sending it to the network via a `ComputeRequest`.
  * The type of the public key corresponds to `CryptoSystem::PublicKey`.

#### `const typename CryptoSystem::PublicKey& network_public_key() const;`

Const version of `network_public_key()`. Returns a constant reference to the network's public key.

```cpp
const auto& networkPk = clientNode.network_public_key();
```

### Usage Example

```cpp
// Create a client node instance
ClientNode clientNode;

// Access the cryptosystem
CryptoSystem& cs = clientNode.crypto_system();

// Generate or obtain plaintext data
PlainTextImpl pt = cs.make_plaintext(123.45f);

// Encrypt the plaintext using the network's public key
CipherTextImpl ct = cs.encrypt(clientNode.network_public_key(), pt);

// Create a compute request
ComputeRequest::ComputeOperationOperand operand(
    ComputeRequest::DataType::SINGLE,
    ComputeRequest::DataEncrytionType::CIPHERTEXT,
    cs.serialize_ciphertext(ct)
);

ComputeRequest::ComputeOperationInstance operation(
    ComputeRequest::ComputeOperationType::UNARY,
    ComputeRequest::ComputeOperation::DECRYPT,
    { operand }
);

ComputeRequest request(operation);

// Perform the computation
ComputeResponse* response = nullptr;
clientNode.compute(request, &response);

// Check the response
if (response && response->status() == ComputeResponse::Status::OK) {
    // Deserialize the result
    PlainTextImpl resultPt = cs.deserialize_plaintext(response->data());
    float result = cs.get_float_from_plaintext(resultPt);
    // Use the result
}
```

### See Also

* [CryptoSystem Interface](https://openvector.gitbook.io/docs/api-references/editor)
* [ComputeRequest Class](https://openvector.gitbook.io/docs/api-references/openapi)
* [ComputeResponse Class](https://openvector.gitbook.io/docs/api-references/computeresponse-class)
