The following diagram shows a high level workflow to encrypt data on the COTI network, it assumes the following is true:
- User account has been created
- User AES key has been created
Flow to encrypt data on-chain
This is the overview of the process, using the data_on_chain.py example from the Python SDK as a reference:
- Overall process to send unencrypted value to network, see method basic_clear_encrypt_decrypt
- First step, method save_clear_value_network_encrypted_in_contract calls a solidity function and sends it a clear value parameter, The network will encrypt that.
- This in turn calls setSomeEncryptedValue from the Solidity contract. This is a transitory state to make the clear value available publicly by having it encrypted using the network AES key.
- Then, Ensure the network block has received clear input correctly using method validate_block_has_tx_input_clear_value. This ensures the relevant block has the clear value sent initially by the user. demonstrating secnario of sending clear value in block but encrypted onchain.
- Next, in order to get back the value encrypted with the AES key of the user, calling save_network_encrypted_to_user_encrypted_in_contract will call the solidity function of setUserSomeEncryptedValue and by that making it publicly available to read by a view.
Demonstrating how to save a network encrypted value by the account that called it (the function). - Get back encrypted value by account using get_user_encrypted_from_contract that calls a view method getUserSomeEncryptedValue
- Decrypt value using decrypt_value
Simple basic flow demonstration of sending a clear value to contract, having it encrypted then reading it back making sure it is what was sent.