Skip to content

Commit 05cdd8a

Browse files
committed
btc: add btc_xpubs()
To fetch multiple xpubs at once, introduced in v9.24.0.
1 parent da5e872 commit 05cdd8a

File tree

12 files changed

+307
-7
lines changed

12 files changed

+307
-7
lines changed

CHANGELOG-rust.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.10.0
4+
- Add `btc_xpubs()`
5+
36
## 0.9.0
47
- Add support for BitBox02 Nova
58

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "bitbox-api"
33
authors = ["Marko Bencun <benma@bitbox.swiss>"]
4-
version = "0.9.0"
4+
version = "0.10.0"
55
homepage = "https://bitbox.swiss/"
66
repository = "https://github.com/BitBoxSwiss/bitbox-api-rs/"
77
readme = "README-rust.md"

README-rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Use `--nocapture` to also see some useful simulator output.
2727
If you want to test against a custom simulator build (e.g. when developing new firmware features),
2828
you can run:
2929

30-
SIMULATOR=/path/to/simulator cargo test --features=simulator,tokio
30+
SIMULATOR=/path/to/simulator cargo test --features=simulator,tokio -- --test-threads 1
3131

3232
In this case, only the given simulator will be used, and the ones defined in simulators.json will be
3333
ignored.

messages/bitbox02_system.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ message DeviceInfoRequest {
2626
}
2727

2828
message DeviceInfoResponse {
29+
message Bluetooth {
30+
// Hash of the currently active Bluetooth firmware on the device.
31+
bytes firmware_hash = 1;
32+
// Firmware version, formated as an unsigned integer "1", "2", etc.
33+
string firmware_version = 2;
34+
// True if Bluetooth is enabled
35+
bool enabled = 3;
36+
}
2937
string name = 1;
3038
bool initialized = 2;
3139
string version = 3;
3240
bool mnemonic_passphrase_enabled = 4;
3341
uint32 monotonic_increments_remaining = 5;
3442
// From v9.6.0: "ATECC608A" or "ATECC608B".
3543
string securechip_model = 6;
44+
// Only present in Bluetooth-enabled devices.
45+
optional Bluetooth bluetooth = 7;
3646
}
3747

3848
message InsertRemoveSDCardRequest {

messages/bluetooth.proto

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2025 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
package shiftcrypto.bitbox02;
17+
18+
message BluetoothToggleEnabledRequest {
19+
}
20+
21+
message BluetoothUpgradeInitRequest {
22+
uint32 firmware_length = 1;
23+
}
24+
25+
message BluetoothChunkRequest {
26+
bytes data = 1;
27+
}
28+
29+
message BluetoothSuccess {
30+
}
31+
32+
message BluetoothRequestChunkResponse {
33+
uint32 offset = 1;
34+
uint32 length = 2;
35+
}
36+
37+
message BluetoothRequest {
38+
oneof request {
39+
BluetoothUpgradeInitRequest upgrade_init = 1;
40+
BluetoothChunkRequest chunk = 2;
41+
BluetoothToggleEnabledRequest toggle_enabled = 3;
42+
}
43+
}
44+
45+
message BluetoothResponse {
46+
oneof response {
47+
BluetoothSuccess success = 1;
48+
BluetoothRequestChunkResponse request_chunk = 2;
49+
}
50+
}

messages/btc.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ message BTCPubRequest {
9393
bool display = 5;
9494
}
9595

96+
message BTCXpubsRequest{
97+
enum XPubType {
98+
UNKNOWN = 0;
99+
XPUB = 1;
100+
TPUB = 2;
101+
}
102+
BTCCoin coin = 1;
103+
XPubType xpub_type = 2;
104+
repeated Keypath keypaths = 3;
105+
}
106+
96107
message BTCScriptConfigWithKeypath {
97108
BTCScriptConfig script_config = 2;
98109
repeated uint32 keypath = 3;
@@ -281,6 +292,7 @@ message BTCRequest {
281292
BTCSignMessageRequest sign_message = 6;
282293
AntiKleptoSignatureRequest antiklepto_signature = 7;
283294
BTCPaymentRequestRequest payment_request = 8;
295+
BTCXpubsRequest xpubs = 9;
284296
}
285297
}
286298

@@ -291,5 +303,6 @@ message BTCResponse {
291303
BTCSignNextResponse sign_next = 3;
292304
BTCSignMessageResponse sign_message = 4;
293305
AntiKleptoSignerCommitment antiklepto_signer_commitment = 5;
306+
PubsResponse pubs = 6;
294307
}
295308
}

messages/common.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ message PubResponse {
1919
string pub = 1;
2020
}
2121

22+
message PubsResponse {
23+
repeated string pubs = 1;
24+
}
25+
2226
message RootFingerprintRequest {
2327
}
2428

messages/hww.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import "common.proto";
1919

2020
import "backup_commands.proto";
2121
import "bitbox02_system.proto";
22+
import "bluetooth.proto";
2223
import "btc.proto";
2324
import "cardano.proto";
2425
import "eth.proto";
@@ -67,6 +68,7 @@ message Request {
6768
ElectrumEncryptionKeyRequest electrum_encryption_key = 26;
6869
CardanoRequest cardano = 27;
6970
BIP85Request bip85 = 28;
71+
BluetoothRequest bluetooth = 29;
7072
}
7173
}
7274

@@ -89,5 +91,6 @@ message Response {
8991
ElectrumEncryptionKeyResponse electrum_encryption_key = 14;
9092
CardanoResponse cardano = 15;
9193
BIP85Response bip85 = 16;
94+
BluetoothResponse bluetooth = 17;
9295
}
9396
}

src/btc.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,27 @@ impl<R: Runtime> PairedBitBox<R> {
643643
}
644644
}
645645

646+
/// Retrieves multiple xpubs. Only standard keypaths are allowed.
647+
pub async fn btc_xpubs(
648+
&self,
649+
coin: pb::BtcCoin,
650+
keypaths: &[Keypath],
651+
xpub_type: pb::btc_xpubs_request::XPubType,
652+
) -> Result<Vec<String>, Error> {
653+
self.validate_version(">=9.24.0")?;
654+
match self
655+
.query_proto_btc(pb::btc_request::Request::Xpubs(pb::BtcXpubsRequest {
656+
coin: coin as _,
657+
xpub_type: xpub_type as _,
658+
keypaths: keypaths.iter().map(|kp| kp.into()).collect(),
659+
}))
660+
.await?
661+
{
662+
pb::btc_response::Response::Pubs(pb::PubsResponse { pubs }) => Ok(pubs),
663+
_ => Err(Error::UnexpectedResponse),
664+
}
665+
}
666+
646667
/// Retrieves a Bitcoin address at the provided keypath.
647668
///
648669
/// For the simple script configs (single-sig), the keypath must follow the

0 commit comments

Comments
 (0)