btcsuite / btcwallet

A secure bitcoin wallet daemon written in Go (golang)
ISC License
1.13k stars 576 forks source link

how to sign a P2WSH script? #930

Closed nghuyenthevinh2000 closed 3 months ago

nghuyenthevinh2000 commented 4 months ago

Hi @Roasbeef,

I am under the impression that SignTransaction will only sign a script ver 0 (P2SH)(https://github.com/btcsuite/btcwallet/blob/master/wallet/wallet.go#L3586)

How can I sign a P2WSH and get that signature into TxIn Witness field? If no one has done that then please give me a quick guide on how to write it in the codebase, and I will submit another Pr.

Currently, I have to dump privkey from btcwallet and then use that private key to sign P2WSH transaction which is not really ideal.

Roasbeef commented 3 months ago

You can use lnd's SignPsbt call. If you can provide a valid PSBT, it'll take care of all the signing for you: https://lightning.engineering/api-docs/api/lnd/wallet-kit/sign-psbt