diff --git a/contrib/requirements/requirements-hw.txt b/contrib/requirements/requirements-hw.txt index a9577d084..95e01b83b 100644 --- a/contrib/requirements/requirements-hw.txt +++ b/contrib/requirements/requirements-hw.txt @@ -4,4 +4,4 @@ safet>=0.1.5 keepkey>=6.3.1 btchip-python>=0.1.32 ckcc-protocol>=0.7.7 -bitbox02>=5.2.0 +bitbox02>=6.0.0 diff --git a/electrum/bitcoin.py b/electrum/bitcoin.py index 64682dd4a..20dbe6db4 100644 --- a/electrum/bitcoin.py +++ b/electrum/bitcoin.py @@ -481,23 +481,30 @@ class OnchainOutputType(Enum): P2SH = enum.auto() WITVER0_P2WPKH = enum.auto() WITVER0_P2WSH = enum.auto() + WITVER1_P2TR = enum.auto() -def address_to_hash(addr: str, *, net=None) -> Tuple[OnchainOutputType, bytes]: +def address_to_payload(addr: str, *, net=None) -> Tuple[OnchainOutputType, bytes]: """Return (type, pubkey hash / witness program) for an address.""" if net is None: net = constants.net if not is_address(addr, net=net): raise BitcoinException(f"invalid bitcoin address: {addr}") witver, witprog = segwit_addr.decode_segwit_address(net.SEGWIT_HRP, addr) if witprog is not None: - if witver != 0: - raise BitcoinException(f"not implemented handling for witver={witver}") - if len(witprog) == 20: - return OnchainOutputType.WITVER0_P2WPKH, bytes(witprog) - elif len(witprog) == 32: - return OnchainOutputType.WITVER0_P2WSH, bytes(witprog) + if witver == 0: + if len(witprog) == 20: + return OnchainOutputType.WITVER0_P2WPKH, bytes(witprog) + elif len(witprog) == 32: + return OnchainOutputType.WITVER0_P2WSH, bytes(witprog) + else: + raise BitcoinException(f"unexpected length for segwit witver=0 witprog: len={len(witprog)}") + elif witver == 1: + if len(witprog) == 32: + return OnchainOutputType.WITVER1_P2TR, bytes(witprog) + else: + raise BitcoinException(f"unexpected length for segwit witver=1 witprog: len={len(witprog)}") else: - raise BitcoinException(f"unexpected length for segwit witver=0 witprog: len={len(witprog)}") + raise BitcoinException(f"not implemented handling for witver={witver}") addrtype, hash_160_ = b58_address_to_hash160(addr) if addrtype == net.ADDRTYPE_P2PKH: return OnchainOutputType.P2PKH, hash_160_ diff --git a/electrum/plugins/bitbox02/bitbox02.py b/electrum/plugins/bitbox02/bitbox02.py index 97750bb30..55e5eaa1a 100644 --- a/electrum/plugins/bitbox02/bitbox02.py +++ b/electrum/plugins/bitbox02/bitbox02.py @@ -482,7 +482,7 @@ class BitBox02Client(HardwareClientBase): ) ) else: - addrtype, pubkey_hash = bitcoin.address_to_hash(txout.address) + addrtype, payload = bitcoin.address_to_payload(txout.address) if addrtype == OnchainOutputType.P2PKH: output_type = bitbox02.btc.P2PKH elif addrtype == OnchainOutputType.P2SH: @@ -491,6 +491,8 @@ class BitBox02Client(HardwareClientBase): output_type = bitbox02.btc.P2WPKH elif addrtype == OnchainOutputType.WITVER0_P2WSH: output_type = bitbox02.btc.P2WSH + elif addrtype == OnchainOutputType.WITVER1_P2TR: + output_type = bitbox02.btc.P2TR else: raise UserFacingException( "Received unsupported output type during transaction signing: {} is not supported by the BitBox02".format( @@ -500,7 +502,7 @@ class BitBox02Client(HardwareClientBase): outputs.append( bitbox02.BTCOutputExternal( output_type=output_type, - output_hash=pubkey_hash, + output_payload=payload, value=txout.value, ) ) @@ -629,7 +631,7 @@ class BitBox02_KeyStore(Hardware_KeyStore): class BitBox02Plugin(HW_PluginBase): keystore_class = BitBox02_KeyStore - minimum_library = (5, 2, 0) + minimum_library = (6, 0, 0) DEVICE_IDS = [(0x03EB, 0x2403)] SUPPORTED_XTYPES = ("p2wpkh-p2sh", "p2wpkh", "p2wsh", "p2wsh-p2sh")