Skip to content

Commit

Permalink
api/firmware/btc: add support for payment requests
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed May 31, 2024
1 parent b22740e commit 5d6a964
Show file tree
Hide file tree
Showing 4 changed files with 812 additions and 310 deletions.
25 changes: 21 additions & 4 deletions api/firmware/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ type BTCTxInput struct {

// BTCTx is the data needed to sign a btc transaction.
type BTCTx struct {
Version uint32
Inputs []*BTCTxInput
Outputs []*messages.BTCSignOutputRequest
Locktime uint32
Version uint32
Inputs []*BTCTxInput
Outputs []*messages.BTCSignOutputRequest
Locktime uint32
PaymentRequests []*messages.BTCPaymentRequestRequest
}

// BTCSign signs a bitcoin or bitcoin-like transaction. The previous transactions of the inputs
Expand Down Expand Up @@ -387,6 +388,22 @@ func (device *Device) BTCSign(
if err != nil {
return nil, err
}
case messages.BTCSignNextResponse_PAYMENT_REQUEST:
paymentRequestIndex := next.Index
if int(paymentRequestIndex) >= len(tx.PaymentRequests) {
return nil, errp.New("payment request index out of bounds")
}
paymentRequest := tx.PaymentRequests[paymentRequestIndex]
next, err = device.nestedQueryBtcSign(
&messages.BTCRequest{
Request: &messages.BTCRequest_PaymentRequest{
PaymentRequest: paymentRequest,
},
},
)
if err != nil {
return nil, err
}
case messages.BTCSignNextResponse_DONE:
return signatures, nil
}
Expand Down
Loading

0 comments on commit 5d6a964

Please sign in to comment.