btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.1k stars 2.31k forks source link

How to construct a schnorr multi-signature transaction #2097

Closed robertcc0410 closed 5 months ago

robertcc0410 commented 5 months ago

give an example

Roasbeef commented 5 months ago

You mean like musig, or using `OP_CHECKSIGADD``?

robertcc0410 commented 5 months ago

You mean like musig, or using `OP_CHECKSIGADD``?

github.com/btcsuite/btcd/btcec/v2/schnorr/musig2
I used signer.Sign(msg), but I have been unable to construct the correct transfer msg. Is msg constructed like this?

    prevOutFetcher := txscript.NewMultiPrevOutFetcher(map[wire.OutPoint]*wire.TxOut{
        *unspentList[0].Outpoint: {
            PkScript: changeScript,
            Value:    unspentList[0].Output.Value,
        },
    })
    sigHashes := txscript.NewTxSigHashes(tx, prevOutFetcher)
    witnessArray, _ := txscript.CalcTaprootSignatureHash(sigHashes, txscript.SigHashDefault, tx, 0, prevOutFetcher)
        ... // sign
        finalSig := combiner.FinalSig()
    tx.TxIn[0].Witness = wire.TxWitness{finalSig.Serialize()}

it reports an error non-mandatory-script-verify-flag (Invalid Schnorr signature),witnessArray is the transaction msg

guggero commented 5 months ago

https://github.com/lightningnetwork/lnd/blob/master/itest/lnd_taproot_test.go#L580