Creates an instance of the Transaction class.
TransactionError:
The parameters for the constructor.
Optional
appParameters required for application-specific transactions.
Contains all the parameters required for a transaction.
The provider used for the transaction.
Optional
shuffleA flag to enable shuffling of UTXOs.
Optional
appParameters required for application-specific transactions.
Optional
merkleContains all the parameters required for a transaction.
The provider used for the transaction.
Optional
remainingThe remaining accounts after the transaction.
Optional
leavesOptional
nullifierA flag to enable shuffling of UTXOs.
The inputs for the transaction.
Optional
encryptedOptional
proofOptional
proofOptional
publicOptional
publicOptional
rootThis method creates a Solana transaction to close the state of the verifier.
appParams
property is set, it uses those parameters to create the instruction.This method is used by applications not the relayer.
TransactionError: If the provider's wallet or the transaction parameters are not properly defined, or if the verifier program is undefined.
Returns a promise that resolves to the transaction signature if the transaction was successfully sent and confirmed.
This asynchronous method prepares proof inputs for a transaction.
It starts by shuffling the UTXOs (Unspent Transaction Outputs) for both inputs and outputs.
The method then fetches the transaction integrity hash and ensures it is defined, otherwise throws an error.
It then proceeds to generate Merkle proofs for the input UTXOs and uses these proofs along with other transaction parameters to build the proofInput
object.
If appParams
are provided, the method calculates the transaction hash accordingly and adds it to the proofInput
object.
Additionally, it prepares the proofInput for the application-specific logic by incorporating appParams.inputs
and public keys of the input UTXOs.
The proofInput
object is used later on in the transaction process to generate zk-SNARK proofs.
TransactionError: Throws an error if the transaction integrity hash is undefined after calling getTxIntegrityHash
.
const transaction = new Transaction(params);
await transaction.compile();
Returns a Promise that resolves when the method has finished executing.
This asynchronous method is an extension of the compile method that includes additional steps.
It not only compiles the transaction which includes preparing proof inputs and arranging the UTXOs in a specific order, but also generates the zk-SNARK proofs, fetches the root index from the on-chain Merkle tree and calculates the Program Derived Addresses (PDAs).
Next, it generates the proof for the transaction. If application parameters (appParams
) are
defined, it generates an additional proof for application-specific logic.
The method then fetches the index of the root of the local Merkle tree in the Merkle tree stored on-chain. This is an important step in validating the transaction, as it verifies that the state of the transaction matches the state of the on-chain Merkle tree.
Finally, it calculates and stores the Program Derived Addresses (PDAs) for the transaction. PDAs are used in the Solana program to handle accounts that are dynamically created during the execution of the program.
Returns a Promise that resolves when the method has finished executing.
This method generates an application-specific proof and assigns the results to 'proofBytesApp' and 'publicInputsApp' of 'transactionInputs'. It is used for general app verifier programs
Will throw an error if 'appParams' is not defined or 'path' is not defined in 'appParams'.
A promise that resolves when the application-specific proof generation and assignment is complete.
This method computes the indices in which the asset for the UTXO is in the asset pubkeys array.
Using these indices, the zero-knowledge proof circuit enforces that only UTXOs containing the assets in the asset pubkeys array
are included in the transaction. This means that the UTXOs that are part of the transaction must correspond to the assets specified
in the assetPubkeysCircuit
array.
TransactionError: If the assetPubkeysCircuit
property is not defined in the params
object.
An array of UTXOs that are part of the transaction.
Returns a three-dimensional array of strings that represent the indices of the assets in the asset pubkeys array.
Asynchronously generates an array of transaction instructions based on the provided transaction parameters.
Object containing the required transaction parameters.
This method returns the mint of the spl token in the utxo.
TransactionError: When the assetPubkeysCircuit property is not available in the transaction parameters.
Returns a Big Number (BN) instance representing the mint value of the transaction.
This method generates and stores PDA (Program Derived Addresses) for nullifier, leaves, and verifier state.
TransactionError: If any of the required properties (transaction inputs, verifier IDL, relayer, remaining accounts) are not properly defined.
myTransaction.getPdaAddresses();
This method generates a proof and assigns the results to 'proofBytes' and 'publicInputs' of 'transactionInputs'. It is used for system verifier programs.
Will throw an error if any issue arises in the 'getProofInternal' method.
A promise that resolves when the proof generation and assignment is complete.
This method generates and verifies a proof.
TransactionError:
An object that contains parameters for the transaction.
The first path to be used by the Prover Class.
A promise that resolves to an object with 'parsedProof' and 'parsedPublicInputsObject'.
For this method the essence is that the merkle tree root index is sent to the program onchain as instruction data instead of the complete root because of two things.
TransactionError:
Returns a promise that resolves when the method has completed. The resolved value is undefined.
This method prepares, sends, and then confirms a transaction on the Solana blockchain.
appParams
property is set, it uses those parameters to get the instructions.TransactionError: If there's an issue with sending the transaction, or if it fails to get the transaction instructions.
const transactionSignature = await myTransaction.sendAndConfirmTransaction();
Returns a promise that resolves to the transaction signature if the transaction was successfully sent and confirmed.
This method sends a transaction to the Solana blockchain.
SHIELD
, the transaction will be sent to a relayer.TransactionError: If the provider's connection, transaction parameters, relayer, root index, or remaining accounts are not properly defined.
const transactionSignature = await myTransaction.sendTransaction(instruction);
The transaction instruction to be sent.
Returns a promise that resolves to the transaction signature if the transaction was successfully sent, or undefined
if there was an issue.
Shuffles the array of Unspent Transaction Outputs (UTXOs) in-place using the Fisher-Yates (aka Knuth) algorithm.
The method is useful when you want to add an additional layer of unpredictability to the transactions.
TransactionError: If the shuffle operation is not enabled.
const shuffledUtxos = shuffleUtxos(utxosArray);
An array of unspent transaction outputs that will be shuffled.
Static
getThis method retrieves the Merkle proofs for each input UTXO where amounts are greater than 0.
TransactionError: If the solMerkleTree
is not defined in the provider object.
const { inputMerklePathIndices, inputMerklePathElements } = Transaction.getMerkleProofs(provider, inputUtxos);
Returns an object that includes two properties: inputMerklePathIndices
and inputMerklePathElements
.
inputMerklePathIndices
is an array of strings representing the indices of the input UTXOs within the Merkle tree.
inputMerklePathElements
is a two-dimensional array of strings representing the path elements of the input UTXOs within the Merkle tree.
Static
getStatic
getThis method derives the Program Derived Address (PDA) for a registered verifier by using the provided Merkle tree and verifier program public keys.
Similar to getSignerAuthorityPda
method, this derived address can be used by the program for additional control and security.
const registeredVerifierPda = Transaction.getRegisteredVerifierPda(merkleTreeProgramId, verifierProgramId);
The public key of the Merkle tree program.
The public key of the verifier program.
Returns the derived PublicKey of the registered verifier PDA.
Static
getThis method derives the Program Derived Address (PDA) for a signer authority by using the provided Merkle tree and verifier program public keys. The PDA serves as an account that the program itself controls, providing an additional layer of security and flexibility in Solana programs.
const signerAuthorityPda = Transaction.getSignerAuthorityPda(merkleTreeProgramId, verifierProgramId);
The public key of the Merkle tree program.
The public key of the verifier program.
Returns the derived PublicKey of the signer authority PDA.
Static
getThis static method retrieves the Program Derived Address (PDA) that is associated with the SPL tokens within the context of the Merkle Tree Program.
The PDA related to the SPL tokens within the context of the Merkle Tree Program.
Static
getThis static method is used to generate the hash of a transaction. It is a poseidon hash that commits to all parameters contained in the shielded transaction (all commitment hashes, and the tx integrity hash).
TransactionError:When the txIntegrityHash property is not available in the transaction parameters.
The transaction parameters object. It should contain the inputUtxos, outputUtxos and txIntegrityHash properties.
The Poseidon hash function instance used for hashing.
Returns a string representing the transaction hash.
Generated using TypeDoc
The Transaction class represents a transaction in the context of the application.