I am using bitcoinjs-lib to construct a transaction through PSBT, but I am having difficulty obtaining the virtual size (vsize). My process is as follows:
Obtain the user's address through the browser wallet (OKX Wallet).
Retrieve the UTXO list for that address via a REST API.
Construct the PSBT, adding inputs and outputs (assuming fee=0 when calculating change).
Send psbt.toHex() to the browser wallet to request the user's signature (unsigned PSBT cannot be finalized).
Calculate the fee using Psbt.fromHex(signResult).extractTransaction().virtualSize() * feeRate.
Recalculate the change based on the fee, resend the modified PSBT to the wallet to request the user's signature, then reconstruct the PSBT from the signature result to get the transaction and broadcast it.
During this process, I need to request the user's signature twice, which results in a poor user experience.
Is there any way to sign only once while still calculating the change based on the actual vsize?