Prepare private inputs
Build Inputtext values from plaintext data so private inputs can be passed into a Bubble contract.
Bubble handles private inputs by encapsulating them within an Inputtext object. To utilize a private input, one must construct an Inputtext instance using their input data.
Each Inputtext instance contains an encrypted value and the address of the user who encrypted it.
The SDK provides two functions to simplify creating Inputtext objects from specified data. One function handles all bit sizes except 256, while a special function is available for the 256-bit size.
The function signatures are provided in Python and JavaScript languages as follows:
def prepare_IT(plaintext, user_aes_key, sender)
def prepare_IT_256(plaintext, user_aes_key, sender)The functions encrypt the plaintext using the AES key to get the ciphertext.
Input parameters:
- plaintext to encrypt
- AES key
- user address (sender)
Output:
- The generated IT that contains the Ciphertext and user address
Both JavaScript and Python 256-bit function, returning output as a singular type. However, Python's version for other bit sizes distinguishes between the ciphertext and the address, returning these as separate values.
Example usage - Private ERC20
When conducting a private amount transfer, the value needs to be converted into an Inputtext format. Below are examples demonstrating how to utilize the prepare IT function:
# Prepare the input text for the function
it = prepare_IT_256(plaintext_integer, user_key, account.address)
# Create the function using the prepared IT
function = contract.functions.transfer(alice_address.address, it)
# Transfer 5 SOD to Alice
execute_transaction(soda_helper, account, contract, function)