Skip to content

Commit

Permalink
Merge #498: bitbox02: implement sign_message()
Browse files Browse the repository at this point in the history
a30d672 bitbox02: update to v5.3.0 (Marko Bencun)
43c60c5 bitbox02: implement sign_message() (Marko Bencun)

Pull request description:

ACKs for top commit:
  achow101:
    ACK a30d672

Tree-SHA512: dcca832716725ad996968a66a1857d0d2654b91af609aa492798562fd06a9910fdd094c40ae0285f7f08fed97e67e9e91c5bf49cf5abd32932445bfe4a968771
  • Loading branch information
achow101 committed Apr 9, 2021
2 parents ecb7b26 + a30d672 commit cecf472
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hwilib/_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def get_client_and_device_info(self, index):
self.client.set_noise_config(BitBox02NoiseConfig())

self.ui.setpass_button.setEnabled(self.device_info['type'] != 'bitbox02')
self.ui.signmsg_button.setEnabled(self.device_info['type'] != 'bitbox02')
self.ui.signmsg_button.setEnabled(True)
self.ui.toggle_passphrase_button.setEnabled(self.device_info['type'] in ('trezor', 'keepkey', 'bitbox02', ))

self.get_device_info()
Expand Down
25 changes: 24 additions & 1 deletion hwilib/devices/bitbox02.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Sequence,
TypeVar,
)
import base64
import builtins
import sys
from functools import wraps
Expand Down Expand Up @@ -782,10 +783,32 @@ def script_config_from_utxo(

return psbt

@bitbox02_exception
def sign_message(
self, message: Union[str, bytes], bip32_path: str
) -> str:
raise UnavailableActionError("The BitBox02 does not support 'signmessage'")
if isinstance(message, str):
message = message.encode("utf-8")
keypath = parse_path(bip32_path)
purpose = keypath[0]
simple_type = {
PURPOSE_P2WPKH: bitbox02.btc.BTCScriptConfig.P2WPKH,
PURPOSE_P2WPKH_P2SH: bitbox02.btc.BTCScriptConfig.P2WPKH_P2SH,
}.get(purpose)
if simple_type is None:
raise BitBox02Error(
"For message signing, the keypath bip44 purpose must be 84' or 49'"
)
_, _, sig65 = self.init().btc_sign_msg(
self._get_coin(),
bitbox02.btc.BTCScriptConfigWithKeypath(
script_config=bitbox02.btc.BTCScriptConfig(
simple_type=simple_type,
),
keypath=keypath,
),
message)
return base64.b64encode(sig65).decode("ascii")

@bitbox02_exception
def toggle_passphrase(self) -> bool:
Expand Down
14 changes: 9 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"
pyside2 = { version = "^5.14.0", optional = true }
bitbox02 = ">=5.2.0,<6.0.0"
bitbox02 = ">=5.3.0,<6.0.0"

[tool.poetry.extras]
qt = ["pyside2"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
modules = \
['hwi', 'hwi-qt']
install_requires = \
['bitbox02>=5.2.0,<6.0.0',
['bitbox02>=5.3.0,<6.0.0',
'ecdsa>=0,<1',
'hidapi>=0,<1',
'libusb1>=1.7,<2.0',
Expand Down

0 comments on commit cecf472

Please sign in to comment.