Skip to content

Commit

Permalink
backend/bitbox02: format BTC as sats if the setting is turned on
Browse files Browse the repository at this point in the history
Also bitbox02-api-go is updated to make use of the new protobuf
messages:

go get github.com/digitalbitbox/bitbox02-api-go@8c31f23
go mod vendor
go mod tidy
  • Loading branch information
benma committed Oct 27, 2022
1 parent 55e2b7e commit 13f2c0b
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 302 deletions.
3 changes: 3 additions & 0 deletions backend/coins/btc/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/btc/maketx"
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/btc/transactions"
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/btc/types"
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/coin"
"github.com/digitalbitbox/bitbox-wallet-app/backend/signing"
"github.com/digitalbitbox/bitbox-wallet-app/util/errp"
)
Expand All @@ -47,6 +48,7 @@ type ProposedTransaction struct {
// Signatures collects the signatures, one per transaction input.
Signatures []*types.Signature
SigHashes *txscript.TxSigHashes
FormatUnit coin.BtcUnit
}

// signTransaction signs all inputs. It assumes all outputs spent belong to this
Expand All @@ -68,6 +70,7 @@ func (account *Account) signTransaction(
GetPrevTx: getPrevTx,
Signatures: make([]*types.Signature, len(txProposal.Transaction.TxIn)),
SigHashes: txscript.NewTxSigHashes(txProposal.Transaction, previousOutputs),
FormatUnit: account.coin.formatUnit,
}

if err := account.Config().Keystore.SignTransaction(proposedTransaction); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions backend/devices/bitbox02/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ func (keystore *keystore) signBTCTransaction(btcProposedTx *btc.ProposedTransact
}
}

formatUnit := messages.BTCSignInitRequest_DEFAULT
if btcProposedTx.FormatUnit == coinpkg.BtcUnitSats {
formatUnit = messages.BTCSignInitRequest_SAT
}
signatures, err := keystore.device.BTCSign(
msgCoin,
scriptConfigs,
Expand All @@ -425,6 +429,7 @@ func (keystore *keystore) signBTCTransaction(btcProposedTx *btc.ProposedTransact
Outputs: outputs,
Locktime: tx.LockTime,
},
formatUnit,
)
if firmware.IsErrorAbort(err) {
return errp.WithStack(keystorePkg.ErrSigningAborted)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/btcsuite/btcd/btcutil v1.1.2
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/cespare/cp v1.1.1 // indirect
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221027102202-8c31f236c498
github.com/ethereum/go-ethereum v1.10.21
github.com/flynn/noise v1.0.0
github.com/gorilla/mux v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRk
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-bitstream v0.0.0-20180413035011-3522498ce2c8/go.mod h1:VMaSuZ+SZcx/wljOQKvp5srsbCiKDEb6K2wC4+PiBmQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c h1:mJl1SA+NVUZGd+LwgRpmLpNyv+kuAhKnEzE+kvIrK+0=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c/go.mod h1:4HNNrzUZC3ew0iuD40MoGp6wAhcDw1UtGYBRjJkJF/k=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221027102202-8c31f236c498 h1:rmgofU3d2ZKU4mYzAfve9g3rmjJ7SVwg1uh+AgwqDt8=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221027102202-8c31f236c498/go.mod h1:4HNNrzUZC3ew0iuD40MoGp6wAhcDw1UtGYBRjJkJF/k=
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ github.com/decred/dcrd/crypto/blake256
github.com/decred/dcrd/dcrec/secp256k1/v4
github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa
github.com/decred/dcrd/dcrec/secp256k1/v4/schnorr
# github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221003094719-2c29561c5a4c
# github.com/digitalbitbox/bitbox02-api-go v0.0.0-20221027102202-8c31f236c498
## explicit
github.com/digitalbitbox/bitbox02-api-go/api/bootloader
github.com/digitalbitbox/bitbox02-api-go/api/common
Expand Down

0 comments on commit 13f2c0b

Please sign in to comment.