Skip to content

Commit

Permalink
api/firmware/bip85: rename BIP85 and add BIP85AppLN()
Browse files Browse the repository at this point in the history
Access to the BIP85 sub-apps BIP39 and LN according to
BitBoxSwiss/bitbox02-firmware#1179.
  • Loading branch information
benma committed Feb 20, 2024
1 parent 2ac5d3d commit be449a9
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 25 deletions.
57 changes: 50 additions & 7 deletions api/firmware/bip85.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,70 @@ import (
"github.com/digitalbitbox/bitbox02-api-go/api/firmware/messages"
"github.com/digitalbitbox/bitbox02-api-go/util/errp"
"github.com/digitalbitbox/bitbox02-api-go/util/semver"
"google.golang.org/protobuf/types/known/emptypb"
)

// BIP85 invokes the BIP-85 workflow on the device, letting the user select the number of words (12,
// 28, 24) and an index and display a derived BIP-39 mnemonic.
func (device *Device) BIP85() error {
if !device.version.AtLeast(semver.NewSemVer(9, 16, 0)) {
return UnsupportedError("9.16.0")
// BIP85AppBip39 invokes the BIP85-BIP39 workflow on the device, letting the user select the number of
// words (12, 28, 24) and an index and display a derived BIP-39 mnemonic.
func (device *Device) BIP85AppBip39() error {
if !device.version.AtLeast(semver.NewSemVer(9, 17, 0)) {
return UnsupportedError("9.17.0")
}

request := &messages.Request{
Request: &messages.Request_Bip85{
Bip85: &messages.BIP85Request{},
Bip85: &messages.BIP85Request{
App: &messages.BIP85Request_Bip39{
Bip39: &emptypb.Empty{},
},
},
},
}
response, err := device.query(request)
if err != nil {
return err
}
_, ok := response.Response.(*messages.Response_Bip85)
bip85Response, ok := response.Response.(*messages.Response_Bip85)
if !ok {
return errp.New("unexpected response")
}
_, ok = bip85Response.Bip85.App.(*messages.BIP85Response_Bip39)
if !ok {
return errp.New("unexpected response")
}
return nil
}

// BIP85AppLN invokes the BIP85-LN workflow on the device, returning 16 bytes of derived entropy for
// use with Breez-SDK.
func (device *Device) BIP85AppLN() ([]byte, error) {
if !device.version.AtLeast(semver.NewSemVer(9, 17, 0)) {
return nil, UnsupportedError("9.17.0")
}

request := &messages.Request{
Request: &messages.Request_Bip85{
Bip85: &messages.BIP85Request{
App: &messages.BIP85Request_Ln{
Ln: &messages.BIP85Request_AppLn{
// Only account_number=0 is allowed for now.
AccountNumber: 0,
},
},
},
},
}
response, err := device.query(request)
if err != nil {
return nil, err
}
bip85Response, ok := response.Response.(*messages.Response_Bip85)
if !ok {
return nil, errp.New("unexpected response")
}
lnResponse, ok := bip85Response.Bip85.App.(*messages.BIP85Response_Ln)
if !ok {
return nil, errp.New("unexpected response")
}
return lnResponse.Ln, nil
}
210 changes: 193 additions & 17 deletions api/firmware/messages/keystore.pb.go

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

14 changes: 14 additions & 0 deletions api/firmware/messages/keystore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
syntax = "proto3";
package shiftcrypto.bitbox02;

import "google/protobuf/empty.proto";

message ElectrumEncryptionKeyRequest {
repeated uint32 keypath = 1;
}
Expand All @@ -13,7 +15,19 @@ message ElectrumEncryptionKeyResponse {
}

message BIP85Request {
message AppLn {
uint32 account_number = 1;
}

oneof app {
google.protobuf.Empty bip39 = 1;
AppLn ln = 2;
}
}

message BIP85Response {
oneof app {
google.protobuf.Empty bip39 = 1;
bytes ln = 2;
}
}
1 change: 0 additions & 1 deletion cmd/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func main() {
info, err := device.DeviceInfo()
errpanic(err)
fmt.Printf("Device info: %+v", info)

//signFromTxID(device, "48e83b2a44c21dab01fc7bad0df1b1d7a59e48af79069454a8320ec6a9d1aefb")

sig, err := device.ETHSignEIP1559(
Expand Down

0 comments on commit be449a9

Please sign in to comment.