Closed kss-espeo closed 4 years ago
The item 5:
- For
P2WPKH
witness program, thescriptCode
is0x1976a914{20-byte-pubkey-hash}88ac
.
Which is the format for P2PKH. So to put it simply: "In regards to the signatureHash, P2WPKH uses P2PKH script instead."
Thanks @junderw . One additional question - in my case, I can't use a private key to directly sign a transaction . Instead, I need to use existing signature to apply it to a pre-built transaction. Therefore, I can't really use Psbt.signInput
. Does Psbt
support that? Should I use https://github.com/bitcoinjs/bitcoinjs-lib/blob/c0718a9f7c41f8235e46e2d015ada2c32021e0c7/src/psbt.js#L520 ?
Hello!
I have a working p2pkh implementation of a wallet transaction. I am able to build transactions and successfully submit them to blockchain. I am looking to improve that implementation to include SegWit (p2wpkh). Specifically I want my code to work with
bech32
addresses which requires being able to both send and receive SegWit transactions, AFAIK .I have put together an implementation, basing on https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts and some other code samples I found around the internet. It's not working for me - the node rejects my transaction with the following message:
Message: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)
.I have also tried to compare hex that my code produced:
with a transaction structure quoted in https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki . It seems correct.
So what am I doing wrong? Please find a Gist with an excerpt from my implementation here: https://gist.github.com/kss-espeo/3accc915348ca3a2f6f246b570a8de49 and an UTXO I am trying to spend here: https://live.blockcypher.com/btc-testnet/tx/bb99dc3b4a3472ddc3108b448a72f09c5636dbaac15eaa5752de764c42732447/