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);
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.
ComputeRequest request = /* ... */;
ComputeResponse* response = nullptr;
clientNode.compute(request, &response);
// Use the response
if (response->status() == ComputeResponse::Status::OK) {
    // Process the result
}- Parameters: - request: A- ComputeRequestobject containing the computation details and input data.
- response: A double pointer to a- ComputeResponseobject where the result will be stored.
 
- Usage Notes: - Ensure that the - responsepointer is initialized to- nullptrbefore passing it to the function.
- After the computation, check the status of the - responseto determine if the computation was successful.
 
CryptoSystem& crypto_system();
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.
CryptoSystem& cs = clientNode.crypto_system();- Usage Notes: - Use this function when you need to perform cryptographic operations without involving the network. 
- The returned - CryptoSystemprovides methods as defined in the CryptoSystem Interface.
 
const CryptoSystem& crypto_system() const;
const CryptoSystem& crypto_system() const;Const version of crypto_system(). Returns a constant reference to the CryptoSystem object.
const CryptoSystem& cs = clientNode.crypto_system();typename CryptoSystem::PublicKey& network_public_key();
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.
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 typename CryptoSystem::PublicKey& network_public_key() const;Const version of network_public_key(). Returns a constant reference to the network's public key.
const auto& networkPk = clientNode.network_public_key();Usage Example
// 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
Last updated