Question to ChatGPT:I create an unsigned PSBT file (P2WPKH) in a watch wallet. I then sign the file offline and import the signed file back into my watch wallet. I can then broadcast the corresponding transaction and the transaction is added to the blockchain. However, when I look at the signed PSBT file, I only find “final_scriptwitness” as an additional value, but no explicit signature. What is the reason for this?
In Bitcoin, when you're working with
P2WPKH (Pay-to-Witness-PubKey-Hash) transactions, the signature is embedded into the
scriptWitness (for SegWit transactions) rather than in the traditional `scriptSig` field used in legacy transactions. This is key to understanding why you only see a `final_scriptwitness` field instead of an explicit signature in the signed PSBT file. Let's walk through this in more detail.
Key Concepts:1.
SegWit (Segregated Witness) Transactions:
- P2WPKH is a SegWit address type, meaning the signature data is stored in the `witness` field rather than in the `scriptSig` field.
- The `witness` is part of the SegWit structure that separates the witness (signature data) from the rest of the transaction data. This helps to reduce transaction size and enable lower fees.
2.
PSBT Structure:
- A Partially Signed Bitcoin Transaction (PSBT) is a container format used to allow multiple parties to sign a transaction in different environments (e.g., one party signs offline, another party signs online).
- The PSBT for a P2WPKH transaction will typically have a `final_scriptwitness`field once it has been signed.
- The `final_scriptwitness` field in the PSBT contains the actual witness stack, which includes the signature, the public key, and any other necessary data for the SegWit script execution.
Specifically, for a
P2WPKH transaction, the `final_scriptwitness` will contain:
- Element 0: The signature (which is what you might expect to see directly).
- Element 1: The public key (needed to verify the signature).
However, the signed PSBT you’re inspecting does not directly show the signature in the traditional format, because SegWit transactions store this signature in the `witness` field, which is represented as the `final_scriptwitness` in the PSBT.
3.
The Reason You Don’t See the Signature in the PSBT File:
- When you sign the PSBT offline, the client (whether it's Bitcoin Core or another wallet) will create a SegWit-compatible witness stack that includes the signature and public key for the relevant input(s).
- For P2WPKH, the final_scriptwitness will contain a witness stack (usually two elements): 1. The signature. 2. The public key.
The
witness stack itself doesn't explicitly look like a signature in a traditional format. Instead, it looks like a data structure that Bitcoin Core (or other wallets) interpret as the
witness for SegWit transactions. The signature is implicitly part of that stack.
So, when you look at the signed PSBT, you're seeing the signed witness data (which includes the signature) instead of a traditional, standalone signature field.