Closed calvinlauyh closed 5 years ago
this is a compound problem:
for other formats, TransactionBuilder is able to accurately guess the prevoutscript.
there is no way to fix this.
So you must hard code your program B to sign as p2wpkh explicitly.
Or
Wait until we merge BIP174 support
Hi @junderw, may I know a bit more of the first solution you suggested? What do you mean by hard code the program B to sign as p2wpkh explictly
? Do you mean to call addInput
inside program B and sign it so that witness data are kept inside the raw transaction hex?
This is extremely hackey... and difficult... but it passes and verifies.
https://github.com/junderw/bitcoinjs-lib/commit/c22564801644f3f101e4fdc8bf60ea062575fb5a
Let me know if you have any questions about it.
Sorry, there has been some time before I get back to my project.
I have tried with the above code snippet and it works well. Thanks for you help.
Just by skimming the methods, the snippet seems to be using the public interface exposed by the class. Do you foresee it will be easily broken when this library further develops and enhances in features?
Sorry I know it is hard to predict code changes, but I am trying to get more sense how reliable I can use the above used functions in my project. Thank you. @junderw
setWitness and hashFor are vital methods and will not likely change in the future, hashFor will likely just add new functions like hashForWitnessV1 when v1 comes out, etc.
I have a scenario where there is a program A that will generate a transaction of multiple P2WPKH inputs and distribute to many different person, each possessing another program B to sign the transaction, once signed, then pass the partly signed tx to next one until everyone is signed.
Here is the pseudo code:
Program A
Program B
However, this does not work and the
bitcoin-cli
will returnnon-mandatory-script-verify-flag (Witness requires empty scriptSig) (code 64)
when trying to send it.I have changed the program to addInput and sign in the same program and it can be broadcasted.
After some investigation, I realize when I do
txBuild.buildIncomplete()
it seems to lose theprevOutScript
of the previous P2PKH output. This make sense because it is not supposed to be inside the transaction hex. But I am wondering how I can let the client (program B) "patch" those information back to the inputs before signing?Thanks