bitcoinjs / bitcoinjs-lib

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

How to make taproot P2TR multiSig wallet #2111

Closed ptc-bink closed 4 months ago

ptc-bink commented 5 months ago

Bitcoinjslib provides us how to make Segwit multisig wallet.

But in my project, I need to provide all of it.

Who can help me?

junderw commented 5 months ago

In taproot there are two ways to make a multisig script. Since CHECKMULTISIG op code was removed for taproot.

  1. "Musig", a method in which you combine N keys into a single key for signing, is more difficult and error prone. We don't offer a simple API to perform that.
  2. Currently, the most secure way of doing multisig in taproot is using the CHECKSIG + CHECKSIGADD + NUMEQUAL method. See the example linked below for an example. If all you want is a single multisig, creating a scriptTree with only a single "leaf" (script) is fine. However, the multisig participants should verify that the key spend (internal pubkey) is unspendable.

https://github.com/bitcoinjs/bitcoinjs-lib/blob/8c88016d8f36e5268d6a3de3c5209e8dc29312e0/test/integration/taproot.spec.ts#L443-L529

I think I'll add a new example with just a simple multisig use case.

junderw commented 5 months ago

I added an example for your use case.

Please ask any questions you might have.

https://github.com/bitcoinjs/bitcoinjs-lib/blob/8d9775c20da03ab40ccbb1971251e71d117bcd8b/test/integration/taproot.spec.ts#L531-L593

ptc-bink commented 4 months ago

Thx for ur kind advice

FCBtc1116 commented 4 months ago

I followed above examples After generate PSBT, I tried to sign PSBT use Unisat wallet but got below error "Can not sign for input #0 with the key 025321d780d099750e7fbcec128213184c9ae0a86241eeacc826c37bce7febc0b8" image

What kind of problem is this?