Bitcoin: Why does walletprocesspsbt finalize the psbt but not return the transaction hex?

Home > Bitcoin: Why does walletprocesspsbt finalize the psbt but not return the transaction hex?

Understanding Bitcoin: Why walletprocesspsbt Finalizes the PSBT but Not Returns the Transaction Hex

As you’re using the popular wallet processpsbt to optionally finalize a Payment Script Binary Tree (PSBT) and add a bip32.derivation path, you’re correct that this command returns a finalized PSBT. However, when adding a new derivation path to an already signed and finalized PSBT, it doesn’t return the transaction hex directly.

In Bitcoin, each transaction’s hash is represented as a 64-byte hexadecimal string. When adding a new derivation path to a PSBT, the wallet processpsbt generates this new hexadecimal representation of the transaction’s hash. This is done by using the bip32.derivation method and then hashing the resulting binary data.

Here’s what happens step-by-step:

  • The wallet processpsbt signs the input transaction with its private key.

  • It creates a Payment Script Binary Tree (PSBT) from the signed transaction, which includes all the necessary information to construct the output.

  • The wallet processpsbt adds a new derivation path to the PSBT using the bip32.derivation method, specifying a custom derivation path.

When you run walletprocesspsbt finalize psbt, it generates a finalized PSBT with the added derivation path. However, instead of returning the transaction hex directly, it returns an object containing the finalized PSBT and other metadata.

Why doesn’t it return the transaction hex?

The wallet processpsbt returns the finalized PSBT because it’s a binary format that represents the payment script tree. The bip32.derivation method uses a hashing algorithm (SHA-256, in this case) to generate the new derivation path and associated hash value.

When you pass the finalized PSBT to an RPC command, such as getrawtransaction, or print its contents using dumpwallet, the wallet processpsbt will return the same object containing the finalized PSBT and other metadata. However, the hex representation of the transaction’s hash is not returned directly; instead, it’s embedded within this object.

Example Use Case:

Suppose you have a signed transaction with a 30-byte input txid and vout indices (e.g., txinmap = [0x1234, 0x5678]). The wallet processpsbt signs the transaction using its private key:

walletprocesspsbt finalize txid vout1 txinmap=0x1234 0x5678 --derivepath=myderivation

After running this command, you get a finalized PSBT containing the signed transaction’s binary data and other metadata. You then add a new derivation path to the PSBT using bip32.derivation:

walletprocesspsbt finalize psbt txid vout1 txinmap=0x1234 0x5678 --derivepath=myderivation --addpath=bip32path

The wallet processpsbt will return an object containing the finalized PSBT and other metadata, including the transaction’s hash as a hexadecimal string.

In summary, when adding a new derivation path to an already signed and finalized PSBT using walletprocesspsbt, the command returns an object containing the finalized PSBT and other metadata. The transaction hex is not directly returned; instead, it’s embedded within this object.

ETHEREUM THAN BLOCK MINS AVERAGE

More Posts

Share:

Send Us A Message