Skip to content

Commit

Permalink
Merge #584: bitbox02: update to v6.0.0, enable sending to Taproot add…
Browse files Browse the repository at this point in the history
…resses

f519d9f bitbox02: update to v6.0.0, enable sending to Taproot addresses (Marko Bencun)

Pull request description:

  Updated pyproject.toml and setup.py, then: `poetry update bitbox02
  --lock`.

ACKs for top commit:
  achow101:
    utACK f519d9f

Tree-SHA512: 33d491e20f6256875672797ea07c8a0e341fb611050978f26fb486e8ff2223b4590ae27553b4eb2f6aefb29048a9dd21ead00199944cd0cca32bc26ecb38d23e
  • Loading branch information
achow101 committed Mar 15, 2022
2 parents 63a4afd + f519d9f commit aa0288c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
14 changes: 14 additions & 0 deletions hwilib/_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def is_p2wsh(script: bytes) -> bool:
return False
return len(wit_prog) == 32

def is_p2tr(script: bytes) -> bool:
"""
Determine whether a script is a P2TR output script.
:param script: The script
:returns: Whether the script is a P2TR output script
"""
is_wit, wit_ver, wit_prog = is_witness(script)
if not is_wit:
return False
elif wit_ver != 1:
return False
return len(wit_prog) == 32


# Only handles up to 15 of 15. Returns None if this script is not a
# multisig script. Returns (m, pubkeys) otherwise.
Expand Down
18 changes: 11 additions & 7 deletions hwilib/devices/bitbox02.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
is_p2pkh,
is_p2wpkh,
is_p2wsh,
is_p2tr,
parse_multisig,
)
from ..psbt import PSBT
Expand Down Expand Up @@ -339,7 +340,7 @@ def send_pin(self, pin: str) -> bool:
"The BitBox02 does not need a PIN sent from the host"
)

def _get_coin(self) -> bitbox02.btc.BTCCoin:
def _get_coin(self) -> "bitbox02.btc.BTCCoin.V":
if self.chain != Chain.MAIN:
return bitbox02.btc.TBTC
return bitbox02.btc.BTC
Expand Down Expand Up @@ -405,7 +406,7 @@ def _multisig_scriptconfig(
self,
threshold: int,
origin_infos: Mapping[bytes, KeyOriginInfo],
script_type: bitbox02.btc.BTCScriptConfig.Multisig.ScriptType,
script_type: "bitbox02.btc.BTCScriptConfig.Multisig.ScriptType.V",
) -> Tuple[bytes, bitbox02.btc.BTCScriptConfigWithKeypath]:
"""
From a threshold, {xpub: KeyOriginInfo} mapping and multisig script type,
Expand Down Expand Up @@ -744,16 +745,19 @@ def script_config_from_utxo(
else:
if tx_out.is_p2pkh():
output_type = bitbox02.btc.P2PKH
output_hash = tx_out.scriptPubKey[3:23]
output_payload = tx_out.scriptPubKey[3:23]
elif is_p2wpkh(tx_out.scriptPubKey):
output_type = bitbox02.btc.P2WPKH
output_hash = tx_out.scriptPubKey[2:]
output_payload = tx_out.scriptPubKey[2:]
elif tx_out.is_p2sh():
output_type = bitbox02.btc.P2SH
output_hash = tx_out.scriptPubKey[2:22]
output_payload = tx_out.scriptPubKey[2:22]
elif is_p2wsh(tx_out.scriptPubKey):
output_type = bitbox02.btc.P2WSH
output_hash = tx_out.scriptPubKey[2:]
output_payload = tx_out.scriptPubKey[2:]
elif is_p2tr(tx_out.scriptPubKey):
output_type = bitbox02.btc.P2TR
output_payload = tx_out.scriptPubKey[2:]
else:
raise BadArgumentError(
"Output type not recognized of output {}".format(output_index)
Expand All @@ -762,7 +766,7 @@ def script_config_from_utxo(
outputs.append(
bitbox02.BTCOutputExternal(
output_type=output_type,
output_hash=output_hash,
output_payload=output_payload,
value=tx_out.nValue,
)
)
Expand Down
44 changes: 39 additions & 5 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mnemonic = "~0"
typing-extensions = "^3.7"
libusb1 = ">=1.7,<3"
pyside2 = { version = "^5.14.0", optional = true, python = "<3.10" }
bitbox02 = ">=5.3.0,<6.0.0"
bitbox02 = ">=6.0.0,<7.0.0"
cbor = "^1.0.0"
pyserial = "^3.5"
dataclasses = {version = "^0.8", python = ">=3.6,<3.7"}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
modules = \
['hwi', 'hwi-qt']
install_requires = \
['bitbox02>=5.3.0,<6.0.0',
['bitbox02>=6.0.0,<7.0.0',
'cbor>=1.0.0,<2.0.0',
'ecdsa>=0,<1',
'hidapi>=0,<1',
Expand Down

0 comments on commit aa0288c

Please sign in to comment.