Skip to content

Commit 4958c8e

Browse files
committed
Merge branch 'psbtSoftware'
2 parents 00b6d56 + cf169f0 commit 4958c8e

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

backend/coins/btc/sign.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/addresses"
2121
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/blockchain"
2222
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/maketx"
23-
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/types"
2423
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
2524
coinpkg "github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/coin"
2625
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/signing"
@@ -38,9 +37,7 @@ type ProposedTransaction struct {
3837
// List of signing configurations that might be used in the tx inputs.
3938
AccountSigningConfigurations signing.Configurations
4039
GetPrevTx func(chainhash.Hash) (*wire.MsgTx, error)
41-
// Signatures collects the signatures, one per transaction input.
42-
Signatures []*types.Signature
43-
FormatUnit coin.BtcUnit
40+
FormatUnit coin.BtcUnit
4441
// GetKeystoreAddress returns the address from the same keystore given the script hash,
4542
// or nil if not found.
4643
GetKeystoreAddress func(coinpkg.Code, blockchain.ScriptHashHex) (*addresses.AccountAddress, error)
@@ -185,7 +182,6 @@ func (account *Account) signTransaction(
185182
AccountSigningConfigurations: signingConfigs,
186183
GetKeystoreAddress: account.getAddressFromSameKeystore,
187184
GetPrevTx: getPrevTx,
188-
Signatures: make([]*types.Signature, len(txProposal.Psbt.UnsignedTx.TxIn)),
189185
FormatUnit: account.coin.formatUnit,
190186
}
191187
if err := proposedTransaction.Update(); err != nil {

backend/devices/bitbox02/keystore_simulator_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ func makeTx(t *testing.T, device *Device, recipient *maketx.OutputInfo) *btc.Pro
489489
}
490490
return nil, nil
491491
},
492-
Signatures: make([]*types.Signature, len(txProposal.Psbt.UnsignedTx.TxIn)),
493492
FormatUnit: coinpkg.BtcUnitDefault,
494493
}
495494
require.NoError(t, proposedTransaction.Update())

backend/keystore/software/software.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
204204
func (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

Comments
 (0)