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 9f0b660
Show file tree
Hide file tree
Showing 4 changed files with 817 additions and 310 deletions.
30 changes: 26 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,27 @@ func (device *Device) BTCSign(
if err != nil {
return nil, err
}
case messages.BTCSignNextResponse_PAYMENT_REQUEST:
outputIndex := next.Index
output := tx.Outputs[outputIndex]
if output.PaymentRequestIndex == nil {
return nil, errp.Newf("payment request index missing from output %d", outputIndex)
}
prIndex := *output.PaymentRequestIndex
if int(prIndex) >= len(tx.PaymentRequests) {
return nil, errp.New("payment request index out of bounds")
}
paymentRequest := tx.PaymentRequests[prIndex]
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 9f0b660

Please sign in to comment.