@@ -20,7 +20,6 @@ import (
2020 "encoding/binary"
2121 "encoding/hex"
2222 "fmt"
23- "math/big"
2423
2524 "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc"
2625 "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/types"
@@ -33,6 +32,7 @@ import (
3332 "github.com/btcsuite/btcd/btcec/v2/ecdsa"
3433 "github.com/btcsuite/btcd/btcec/v2/schnorr"
3534 "github.com/btcsuite/btcd/btcutil/hdkeychain"
35+ "github.com/btcsuite/btcd/btcutil/psbt"
3636 "github.com/btcsuite/btcd/chaincfg"
3737 "github.com/btcsuite/btcd/txscript"
3838 ethTypes "github.com/ethereum/go-ethereum/core/types"
@@ -204,7 +204,6 @@ func (keystore *Keystore) BTCXPubs(
204204func (keystore * Keystore ) signBTCTransaction (btcProposedTx * btc.ProposedTransaction ) error {
205205 keystore .log .Info ("Sign transaction." )
206206 transaction := btcProposedTx .TXProposal .Psbt .UnsignedTx
207- signatures := make ([]* types.Signature , len (transaction .TxIn ))
208207 sigHashes := btcProposedTx .TXProposal .SigHashes ()
209208 for index , txIn := range transaction .TxIn {
210209 spentOutput , ok := btcProposedTx .TXProposal .PreviousOutputs [txIn .PreviousOutPoint ]
@@ -242,11 +241,7 @@ func (keystore *Keystore) signBTCTransaction(btcProposedTx *btc.ProposedTransact
242241 if err != nil {
243242 return err
244243 }
245- signatureSer := signature .Serialize ()
246- signatures [index ] = & types.Signature {
247- R : new (big.Int ).SetBytes (signatureSer [:32 ]),
248- S : new (big.Int ).SetBytes (signatureSer [32 :]),
249- }
244+ btcProposedTx .TXProposal .Psbt .Inputs [index ].TaprootKeySpendSig = signature .Serialize ()
250245 } else {
251246 var signatureHash []byte
252247 isSegwit , subScript := address .ScriptForHashToSign ()
@@ -267,16 +262,16 @@ func (keystore *Keystore) signBTCTransaction(btcProposedTx *btc.ProposedTransact
267262 }
268263 keystore .log .Debug ("Calculated legacy signature hash" )
269264 }
270- signature := ecdsa .SignCompact (prv , signatureHash , true )
271-
272- signatures [index ] = & types.Signature {
273- R : new (big.Int ).SetBytes (signature [1 :33 ]),
274- S : new (big.Int ).SetBytes (signature [33 :]),
265+ signature := ecdsa .Sign (prv , signatureHash ).Serialize ()
266+ btcProposedTx .TXProposal .Psbt .Inputs [index ].PartialSigs = []* psbt.PartialSig {
267+ {
268+ PubKey : prv .PubKey ().SerializeCompressed (),
269+ Signature : append (signature , byte (txscript .SigHashAll )),
270+ },
275271 }
276272 }
277273 }
278274
279- btcProposedTx .Signatures = signatures
280275 return nil
281276}
282277
0 commit comments