Creates an instance of TransactionParameters.
TransactionParametersError: If no output UTXOs and input UTXOs are provided, no verifier IDL is provided, no Poseidon hasher is provided, no action is defined, message Merkle tree pubkey needs to be defined if a message is provided, message needs to be defined if a message Merkle tree is provided, etc.
An object containing the parameters for the transaction.
Action to perform in the transaction.
Optional
ataOptional flag indicating whether to include the ATA creation fee in the transaction.
Optional
encryptedOptional encrypted UTXOs for the transaction.
Optional
inputOptional array of input UTXOs for the transaction.
Optional
lookOptional lookup table for the transaction.
Optional
message?: BufferOptional message for the transaction.
Optional
messageOptional public key of the message Merkle tree.
Optional
outputOptional array of output UTXOs for the transaction.
Poseidon hasher for the transaction.
Optional
provider?: ProviderOptional provider for the transaction.
Optional
recipientOptional public key of the recipient for SOL transactions.
Optional
recipientOptional public key of the recipient for SPL transactions.
Optional
relayer?: RelayerOptional relayer for the transaction.
Optional
senderOptional public key of the sender for SOL transactions.
Optional
senderOptional public key of the sender for SPL transactions.
Public key of the transaction Merkle tree.
Nonce for the transaction.
Optional
validateOptional flag indicating whether to validate UTXOs in the transaction.
Interface description language for the transaction verifier.
Optional
ataOptional
encryptedOptional
messageOptional
txAdds empty UTXOs to the given array until the array reaches a specified length.
The zero-knowledge proof circuit requires all inputs to be defined, hence the need to populate the array with empty UTXOs when necessary. This function ensures that the number of UTXOs in the array matches the expected number as defined by the zk-SNARKs protocol.
The array of UTXOs to which empty UTXOs will be added. Default is an empty array.
The desired number of UTXOs in the array after the function is executed.
An array of UTXOs of the desired length, populated with empty UTXOs as needed.
This method assigns sender and recipient accounts for Solana and SPL tokens to the transaction parameters based on the action (either 'unshield', 'transfer', or 'shield').
For 'unshield' and 'transfer' actions, it assigns the sender accounts for both SPL and Solana tokens and checks if the recipient accounts are defined. If not, it throws an error.
For the 'shield' action, it assigns the recipient accounts and checks if the sender accounts are defined. If not, it throws an error.
TransactionParametersError:
If the action is 'unshield' or 'transfer' and the recipient accounts for SPL or Solana tokens are undefined.
If the action is 'shield' and the sender accounts for SPL or Solana tokens are undefined.
If the assetPubkeys are undefined.
If the action is not 'deposit' but should be, based on the provided sender and recipient accounts and relayer.
This method is used to encrypt the output UTXOs.
It first checks if there are encrypted UTXOs provided. If so, it uses those as the encrypted outputs. If not, it goes through the output UTXOs for this transaction. If the UTXO has application data and this is to be included, it throws an error as this is currently not implemented. Otherwise, it encrypts the UTXO and adds it to the list of encrypted outputs.
Depending on the verifier configuration, it either combines two encrypted outputs into a single 256 byte output or adds padding to the encrypted outputs to ensure their length is correct.
The poseidon hash function.
Optional
encryptedUtxos: Uint8ArrayAn optional parameter for previously encrypted UTXOs.
Computes the integrity Poseidon hash over transaction inputs that are not part of the proof, but are included to prevent the relayer from changing any input of the transaction.
The hash is computed over the following inputs in the given order:
Throws an error if the relayer, recipient SPL or Solana accounts, relayer fee, or encrypted UTXOs are undefined, or if the encryption of UTXOs fails.
const integrityHash = await getTxIntegrityHash(poseidonInstance);
Poseidon hash function instance.
A promise that resolves to the computed transaction integrity hash.
Asynchronously converts transaction parameters to bytes using the BorshAccountsCoder.
This method performs the following operations:
inputUtxos
array to bytes and stores them in inputUtxosBytes
.outputUtxos
array to bytes and stores them in outputUtxosBytes
.outputUtxosBytes
, inputUtxosBytes
, relayerPubkey
, relayerFee
, current object's properties, accounts' properties, and transactionNonce
(converted to a BN instance).Throws an error if the encoding fails.
A promise that resolves to a Buffer containing the encoded transaction parameters.
Static
findA static method to find the index of a specific IDL object in an array of IDL objects based on a given program ID.
If an IDL object in the provided array does not have any constants.
let index = TransactionParameters.findIdlIndex("someProgramId", idlArray);
if(index !== -1) {
console.log("Program ID found at index: " + index);
}
The ID of the program for which to find the IDL object.
An array of IDL objects among which to search.
The index of the IDL object that contains the provided program ID. Returns -1 if the program ID is not found.
Static
fromA static method to create a new TransactionParameters instance from a given set of bytes.
This method decodes the provided bytes using a BorshAccountsCoder and checks the validity of the resulting data. It retrieves the input and output UTXOs from the decoded data, ensuring that they match the provided IDLs. It also checks that the relayer's public key matches the one in the decoded data.
If the decoded recipient is not the AUTHORITY, the action is set to UNSHIELD, otherwise, it's set to TRANSFER. The method then creates a new TransactionParameters instance with the retrieved data and returns it.
Throws a TransactionParametersError if the UTXO IDLs are not provided when needed, or if the relayer's public key does not match the one in the decoded data.
The parameters for the method.
The bytes to decode into a TransactionParameters instance.
The Poseidon hash function instance.
The relayer for the transaction.
Optional
utxoAn optional array of IDLs for the UTXOs.
The IDL of the verifier program.
A promise that resolves to a new TransactionParameters instance.
Static
getThis method collects and returns public keys of assets involved in a transaction, from both input and output UTXOs. It also checks whether the number of different assets involved in the transaction exceeds the maximum limit. If there are less assets than the maximum allowed, it fills up the remaining space with the System Program's public key.
Static
getThis method generates a Program Derived Address (PDA) with the seed "escrow" for the verifier program. PDAs in Solana are addresses that are based off of the public key of a deployed program and are unique to each specific program and seed. This method is used to get the PDA that is used as the escrow account.
The public key of the verifier program.
Static
getThis method calculates the external amount for a specified asset. It achieves this by adding all output UTXOs of the same asset and subtracting all input UTXOs of the same asset. The result is then added to the field size and the modulus of the field size is returned.
Static
getStatic async method to generate transaction parameters.
The method constructs a TransactionParameters object which includes all the necessary parameters for a transaction. It selects the necessary input UTXOs, creates the output UTXOs, and validates the relayer and action of the transaction. It also handles various transaction actions like shield, unshield and transfer.
Parameters for generating transaction parameters.
The account involved in the transaction.
The action being performed (shield, unshield, transfer).
Optional
addWhether to add input UTXOs to the transaction.
Optional
addWhether to add output UTXOs to the transaction.
Optional
appThe configuration for the application UTXO.
Optional
ataWhether to include the ATA (Associated Token Account) creation fee.
Optional
inArray of input UTXOs for the transaction.
Optional
mergeWhether to merge UTXOs in the transaction.
Optional
message?: BufferThe message data for the transaction.
Optional
outArray of output UTXOs for the transaction.
The provider for the transaction.
Optional
publicThe amount of SOL tokens involved in the transaction.
Optional
publicThe amount of SPL tokens involved in the transaction.
Optional
recipientThe Solana address of the recipient.
Optional
recipientThe SPL address of the recipient.
Optional
relayer?: RelayerThe relayer for the transaction.
The context of the token involved in the transaction.
The nonce for the transaction.
Optional
userThe SPL account of the user.
Optional
utxos?: Utxo[]Array of UTXO (Unspent Transaction Outputs) objects.
The IDL (Interface Description Language) for the verifier program.
Static
getA static method to fetch the verifier configuration from a given IDL object.
This method parses the IDL object to identify an account with a name
that starts with "zK" and ends with "ProofInputs". It then examines the fields
of this account to identify the inputNullifier
and outputCommitment
fields,
checking that they are of the correct array type, and retrieves their lengths.
The lengths of these fields are then returned as a VerifierConfig object.
Throws an error if no matching account is found in the IDL, or if the inputNullifier
or outputCommitment
fields are not found or are of incorrect type.
The IDL object of the verifier program.
A VerifierConfig object with the lengths of the inputNullifier
and outputCommitment
fields.
Static
getA static method to instantiate a new verifier program from a given IDL object.
The programID is expected to be appended as a constant to the program that can be read directly from the IDL.
The IDL object of the verifier program.
A new Anchor Program object for the verifier program.
Static
getA static method to retrieve the verifier program ID from a given IDL object.
let verifierProgramId = TransactionParameters.getVerifierProgramId(verifierIdl);
console.log("Verifier program ID: " + verifierProgramId);
The programID is expected to be appended as a constant to the program that can be read directly from the IDL.
The IDL object containing the verifier program ID.
The verifier program ID as a PublicKey object.
Generated using TypeDoc
A class that represents the parameters required for a transaction.