Skip to content

Commit 373383e

Browse files
committed
bitcoin: add regtest support
It has a different bech32 address HRP (prefix). Third party integrations sometimes are missing this and use testnet as a workaround, but proper support is nicer.
1 parent 0b2085b commit 373383e

File tree

13 files changed

+52
-12
lines changed

13 files changed

+52
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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: add support for regtest
1011

1112
### 9.20.0
1213
- Bitcoin: UX improvements for payment request confirmations

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ endif()
9696
#
9797
# Versions MUST contain three parts and start with lowercase 'v'.
9898
# Example 'v1.0.0'. They MUST not contain a pre-release label such as '-beta'.
99-
set(FIRMWARE_VERSION "v9.20.0")
100-
set(FIRMWARE_BTC_ONLY_VERSION "v9.20.0")
99+
set(FIRMWARE_VERSION "v9.21.0")
100+
set(FIRMWARE_BTC_ONLY_VERSION "v9.21.0")
101101
set(BOOTLOADER_VERSION "v1.0.6")
102102

103103
find_package(PythonInterp 3.6 REQUIRED)

messages/btc.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ enum BTCCoin {
2424
TBTC = 1;
2525
LTC = 2;
2626
TLTC = 3;
27+
// Regtest
28+
RBTC = 4;
2729
};
2830

2931

py/bitbox02/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# 8.0.0
66
- SD card: Remove API to prompt removal of the microSD card from the device
7+
- Add support for regtest (supported from firmware version v9.21.0)
78

89
# 7.0.0
910
- get_info: add optional device initialized boolean to returned tuple

py/bitbox02/bitbox02/bitbox02/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from __future__ import print_function
1717
import sys
1818

19-
__version__ = "7.0.0"
19+
__version__ = "8.0.0"
2020

2121
if sys.version_info.major != 3 or sys.version_info.minor < 6:
2222
print(

py/bitbox02/bitbox02/communication/generated/btc_pb2.py

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02/bitbox02/communication/generated/btc_pb2.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ class _BTCCoinEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTy
2323
TBTC: _BTCCoin.ValueType # 1
2424
LTC: _BTCCoin.ValueType # 2
2525
TLTC: _BTCCoin.ValueType # 3
26+
RBTC: _BTCCoin.ValueType # 4
27+
"""Regtest"""
28+
2629
class BTCCoin(_BTCCoin, metaclass=_BTCCoinEnumTypeWrapper):
2730
pass
2831

2932
BTC: BTCCoin.ValueType # 0
3033
TBTC: BTCCoin.ValueType # 1
3134
LTC: BTCCoin.ValueType # 2
3235
TLTC: BTCCoin.ValueType # 3
36+
RBTC: BTCCoin.ValueType # 4
37+
"""Regtest"""
38+
3339
global___BTCCoin = BTCCoin
3440

3541

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub async fn antiklepto_get_host_nonce(
8888
fn coin_enabled(coin: pb::BtcCoin) -> Result<(), Error> {
8989
use pb::BtcCoin::*;
9090
#[cfg(feature = "app-bitcoin")]
91-
if let Btc | Tbtc = coin {
91+
if let Btc | Tbtc | Rbtc = coin {
9292
return Ok(());
9393
}
9494
#[cfg(feature = "app-litecoin")]
@@ -580,7 +580,7 @@ mod tests {
580580
assert!(block_on(process_pub(&req_invalid)).is_err());
581581
// -- Wrong coin: MAX + 1
582582
let mut req_invalid = req.clone();
583-
req_invalid.coin = BtcCoin::Tltc as i32 + 1;
583+
req_invalid.coin = BtcCoin::Rbtc as i32 + 1;
584584
assert!(block_on(process_pub(&req_invalid)).is_err());
585585
}
586586

@@ -690,6 +690,15 @@ mod tests {
690690
expected_address: "tb1qnlyrq9pshg0v0lsuudjgga4nvmjxhcvketqwdg",
691691
expected_display_title: "BTC Testnet",
692692
},
693+
// RBTC P2WPKH
694+
Test {
695+
mnemonic: TEST_MNEMONIC,
696+
coin: BtcCoin::Rbtc,
697+
keypath: &[84 + HARDENED, 1 + HARDENED, 0 + HARDENED, 0, 0],
698+
simple_type: SimpleType::P2wpkh,
699+
expected_address: "bcrt1qnlyrq9pshg0v0lsuudjgga4nvmjxhcvkmzer6p",
700+
expected_display_title: "BTC Regtest",
701+
},
693702
// LTC P2WPKH-P2SH
694703
Test {
695704
mnemonic: TEST_MNEMONIC,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ pub fn format_amount(
4747
FormatUnit::Default => (8, "TBTC"),
4848
FormatUnit::Sat => (0, "tsat"),
4949
},
50+
BtcCoin::Rbtc => match format_unit {
51+
FormatUnit::Default => (8, "RBTC"),
52+
FormatUnit::Sat => (0, "rsat"),
53+
},
5054
BtcCoin::Ltc => match format_unit {
5155
FormatUnit::Default => (8, "LTC"),
5256
_ => return Err(Error::InvalidInput),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub fn get_hash(
5555
BtcCoin::Tbtc => 0x01,
5656
BtcCoin::Ltc => 0x02,
5757
BtcCoin::Tltc => 0x03,
58+
BtcCoin::Rbtc => 0x04,
5859
};
5960
hasher.update(byte.to_le_bytes());
6061
}
@@ -204,14 +205,14 @@ pub async fn confirm_extended(
204205
ScriptType::P2wsh => bip32::XPubType::CapitalZpub,
205206
ScriptType::P2wshP2sh => bip32::XPubType::CapitalYpub,
206207
},
207-
BtcCoin::Tbtc | BtcCoin::Tltc => match script_type {
208+
BtcCoin::Tbtc | BtcCoin::Rbtc | BtcCoin::Tltc => match script_type {
208209
ScriptType::P2wsh => bip32::XPubType::CapitalVpub,
209210
ScriptType::P2wshP2sh => bip32::XPubType::CapitalUpub,
210211
},
211212
},
212213
XPubType::AutoXpubTpub => match params.coin {
213214
BtcCoin::Btc | BtcCoin::Ltc => bip32::XPubType::Xpub,
214-
BtcCoin::Tbtc | BtcCoin::Tltc => bip32::XPubType::Tpub,
215+
BtcCoin::Tbtc | BtcCoin::Rbtc | BtcCoin::Tltc => bip32::XPubType::Tpub,
215216
},
216217
};
217218
let num_cosigners = multisig.xpubs.len();

0 commit comments

Comments
 (0)