bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.68k stars 2.1k forks source link

[Question] Partial signing a multisignature script. #1602

Closed educob closed 4 years ago

educob commented 4 years ago

Hi.

In test example 'can create (and broadcast via 3PBP) a typical Transaction' it's shown how to sign a tx by several people who could be in different places/times by doing:

const psbtBaseText = psbt.toBase64();
const signer1 = bitcoin.Psbt.fromBase64(psbtBaseText);
signer1.signAllInputs(alice1.keys[0]);
const s1text = signer1.toBase64();
const final1 = bitcoin.Psbt.fromBase64(s1text);
...
psbt.combine(final1, final2);
psbt.finalizeAllInputs();

I'd like to confirm that this is also the way to proceed with multisignature scripts (and generic scripts).

Thanks.

junderw commented 4 years ago

Yes. If you try to finalize an input that is multisig but it only has one partialSig object when it needs 2, the finalize command will fail.

Export the PSBT, send to other signer, import, sign, THEN you can finalize. (who does the finalizing and broadcasting doesn't matter in regards to PSBT, and is merely a security consideration for you app depending on how the multisig is set up)