Utxo class represents an unspent transaction output (UTXO) in Tornado Nova. A complete transaction consists of 2-16 input UTXOs and 2 output UTXOs.
Constructor
Initialize a new UTXO with optional parameters.Parameters
The UTXO amount in wei. Can be 0 for dummy UTXOs used to pad transactions.
The keypair that owns this UTXO. If not provided, a random keypair is generated.
A random blinding factor used in commitment calculation. Auto-generated if not provided.
The UTXO’s position in the Merkle tree. Required for spending the UTXO.
Methods
getCommitment()
Returns the commitment for this UTXO. The commitment is calculated using Poseidon hash of the amount, public key, and blinding factor.BigNumber - The commitment value
Commitments are cached after first calculation for performance.
getNullifier()
Returns the nullifier for this UTXO. The nullifier is used to prevent double-spending.BigNumber - The nullifier value
Throws: Error if the UTXO has amount > 0 but missing index or private key
To compute a nullifier, the UTXO must have:
- A non-zero amount
- A valid index in the Merkle tree
- A keypair with a private key
encrypt()
Encrypts the UTXO data (amount and blinding factor) using the keypair’s encryption key.string - Hex string with 0x prefix containing encrypted data
The encrypted data includes:
- Amount (31 bytes)
- Blinding factor (31 bytes)
decrypt() (static)
Decrypts UTXO data and creates a new Utxo instance.The keypair used to decrypt the data
Hex string with encrypted UTXO data
The UTXO’s index in the Merkle tree
Utxo - A new Utxo instance with decrypted data
Example usage
Creating a deposit UTXO
Creating dummy UTXOs
Transactions require exactly 2 or 16 inputs and 2 outputs. Use dummy UTXOs with amount 0 to pad:Decrypting received UTXOs
Spending a UTXO
Properties
After construction, a Utxo instance has these properties:amount- BigNumber representing the UTXO amountblinding- BigNumber representing the blinding factorkeypair- The Keypair that owns this UTXOindex- Number or null, the Merkle tree index
Related
- Keypair class - Key management
- Transactions - Using UTXOs in transactions