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

Understanding Bitcoin: Why walletprocesspsbt completes the PSBT but doesn’t return the transaction hex

Since you are using the popular wallet processpsbt to optionally complete a Payment Script Binary Tree (PSBT) and add a bip32.derivation path, you are correct that this command returns a completed PSBT. However, if a new derivation path is added to an already signed and completed PSBT, the transaction hex is not returned directly.

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

Here’s how it works, step by step:

  • The wallet process PSbt signs the input transaction with its private key.
  • It creates a Payment Script Binary Tree (PSBT) from the signed transaction.
  • The wallet processpsbt adds a new derivation path to the PSBT using the bip32.derivation method and specifies a custom derivation path.

Running walletprocesspsbt finalize psbt 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 process PSBT returns the finalized PSBT because it is a binary format representing the payment script tree. The bip32.derivation method uses a hashing algorithm (SHA-256 in this case) to generate the new derivation path and the associated hash value.

When you pass the finalized PSBT to an RPC command such as “gettransaction” or print its contents with “dumpwallet”, the wallet process “psbt” returns the same object containing the finalized PSBT and other metadata. However, the hex representation of the transaction’s hash is not returned directly, but is embedded in 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 processpsbt wallet signs the transaction with its private key:

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

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

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

The processpsbt wallet returns an object containing the finalized PSBT and other metadata, including the hash of the transaction as a hexadecimal string.

To summarize, 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 returned directly, but is embedded in this object.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *