Skip to content

Commit 63be2e5

Browse files
committed
bitcoin: enable message signing on testnet and regtest
Fixes #1376
1 parent 967939f commit 63be2e5

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
77
## Firmware
88

99
### [Unreleased]
10+
- Bitcoin: enable message signing on testnet and regtest
1011

1112
### 9.22.0
1213
- Update manufacturer HID descriptor to bitbox.swiss

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ endif()
9191
#
9292
# Versions MUST contain three parts and start with lowercase 'v'.
9393
# Example 'v1.0.0'. They MUST not contain a pre-release label such as '-beta'.
94-
set(FIRMWARE_VERSION "v9.22.0")
95-
set(FIRMWARE_BTC_ONLY_VERSION "v9.22.0")
94+
set(FIRMWARE_VERSION "v9.23.0")
95+
set(FIRMWARE_BTC_ONLY_VERSION "v9.23.0")
9696
set(BOOTLOADER_VERSION "v1.1.0")
9797

9898
find_package(PythonInterp 3.6 REQUIRED)

py/bitbox02/bitbox02/bitbox02/bitbox02.py

+2
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,8 @@ def btc_sign_msg(
607607
# pylint: disable=no-member
608608

609609
self._require_atleast(semver.VersionInfo(9, 2, 0))
610+
if coin in (btc.TBTC, btc.RBTC):
611+
self._require_atleast(semver.VersionInfo(9, 23, 0))
610612

611613
request = btc.BTCRequest()
612614
request.sign_message.CopyFrom(

src/rust/bitbox02-rust/src/hww/api/bitcoin/signmsg.rs

+66-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const MAX_MESSAGE_SIZE: usize = 1024;
3636
/// compact format (R and S values), and the last byte is the recoverable id (recid).
3737
pub async fn process(request: &pb::BtcSignMessageRequest) -> Result<Response, Error> {
3838
let coin = BtcCoin::try_from(request.coin)?;
39-
if coin != BtcCoin::Btc {
39+
if !matches!(coin, BtcCoin::Btc | BtcCoin::Tbtc | BtcCoin::Rbtc) {
4040
return Err(Error::InvalidInput);
4141
}
4242
let (keypath, simple_type) = match &request.script_config {
@@ -182,6 +182,52 @@ mod tests {
182182
);
183183
}
184184

185+
#[test]
186+
pub fn test_p2wpkh_testnet() {
187+
let request = pb::BtcSignMessageRequest {
188+
coin: BtcCoin::Tbtc as _,
189+
script_config: Some(pb::BtcScriptConfigWithKeypath {
190+
script_config: Some(pb::BtcScriptConfig {
191+
config: Some(Config::SimpleType(SimpleType::P2wpkh as _)),
192+
}),
193+
keypath: vec![84 + HARDENED, 1 + HARDENED, 0 + HARDENED, 0, 0],
194+
}),
195+
msg: MESSAGE.to_vec(),
196+
host_nonce_commitment: None,
197+
};
198+
199+
static mut CONFIRM_COUNTER: u32 = 0;
200+
201+
mock(Data {
202+
ui_confirm_create: Some(Box::new(|params| {
203+
match unsafe {
204+
CONFIRM_COUNTER += 1;
205+
CONFIRM_COUNTER
206+
} {
207+
1 => {
208+
assert_eq!(params.title, "Sign message");
209+
assert_eq!(params.body, "Coin: BTC Testnet");
210+
true
211+
}
212+
2 => {
213+
assert_eq!(params.title, "Address");
214+
assert_eq!(params.body, "tb1qnlyrq9pshg0v0lsuudjgga4nvmjxhcvketqwdg");
215+
true
216+
}
217+
3 => {
218+
assert_eq!(params.title, "Sign message");
219+
assert_eq!(params.body.as_bytes(), MESSAGE);
220+
true
221+
}
222+
_ => panic!("too many user confirmations"),
223+
}
224+
})),
225+
..Default::default()
226+
});
227+
mock_unlocked();
228+
assert!(block_on(process(&request)).is_ok());
229+
}
230+
185231
#[test]
186232
pub fn test_p2wpkh_p2sh() {
187233
let request = pb::BtcSignMessageRequest {
@@ -419,5 +465,24 @@ mod tests {
419465
})),
420466
Err(Error::InvalidInput)
421467
);
468+
// Invalid keypath (mainnet keypath on testnet)
469+
mock(Data {
470+
..Default::default()
471+
});
472+
mock_unlocked();
473+
assert_eq!(
474+
block_on(process(&pb::BtcSignMessageRequest {
475+
coin: BtcCoin::Tbtc as _,
476+
script_config: Some(pb::BtcScriptConfigWithKeypath {
477+
script_config: Some(pb::BtcScriptConfig {
478+
config: Some(Config::SimpleType(SimpleType::P2wpkh as _))
479+
}),
480+
keypath: vec![84 + HARDENED, 0 + HARDENED, 0 + HARDENED, 0, 0],
481+
}),
482+
msg: MESSAGE.to_vec(),
483+
host_nonce_commitment: None,
484+
})),
485+
Err(Error::InvalidInput)
486+
);
422487
}
423488
}

0 commit comments

Comments
 (0)