Comment on page

Encrypting Inputs

TypeScript/JavaScript
Python (LocalFhenix Only)
In JavaScript we'll use fhevmjs to encrypt the data
import * as fhevmjs from 'fhevmjs';
const encrypt = async (input: number): Uint8Array => {
const instance = fhevmjs.createInstance({
chainId: 8011,
publicKey: tfhePublicKey,
});
const resultUint32 = instance.encrypt32(input);
return resultUint32
}
LocalFhenix includes a built-in encryption service, which can be used for debugging and development purposes (not available on Devnet)
import requests
def encrypt_number(number: int, int_size: int = 32) -> str:
# Set the base URL
base_url = "http://localhost:5000/encrypt"
# Set the query parameters
params = {
"number": number,
"int": int_size
}
# Send the GET request
response = requests.get(base_url, params=params)
# Check if the request was successful
if response.status_code == 200:
# Return the encrypted number
return response.text
else:
# Print an error message and return None if the request was not successful
print(f"Request failed with status code {response.status_code}")
return None
# Example usage:
encrypted_number = encrypt_number(259, 16)
print(encrypted_number)