Defining functions
Constructor
Define a constructor such that whoever created the contract is the owner of the token.
Minting Tokens:
mint
function to create new tokens, updatingtotalSupply
and the owner's balance. We use TFHE operations to add tokens to the owner's balance. When user sends ciphertext as bytes, we need to convert it to the respective integer type to ensure it's well formed.
Transferring Tokens:
transfer
function that allows token holders to send tokens to another address. We use TFHE operations for encrypted checks (e.g., balance sufficiency) and updates. optReq is the equivalent of Solidity's require, but for TFHE data types.
Approving Tokens:
approve
function enables token holders to set an allowance for another address.
Transferring Tokens from Another Address:
transferFrom
function should enable a spender to transfer tokens within the allowance set for them.
Viewing encrypted balances and allowances:
Balances:
We implement a function that allows the user to see their own encrypted balance. This is done by re-encrypting the balance with the user's public key. The user can then decrypt their own balance on the frontend using the associated private key.
Allowances:
Similarly, we write a function to view the encrypted allowance set for a spender by the contract creator, using re-encryption for confidentiality.
Total Supply:
We write a function getTotalSupply to allow only the contract creator to view the encrypted total supply using re-encryption.
Last updated