Skip to content

Commit 2c07fc7

Browse files
authored
Merge pull request #1454 from NickeZ/nickez/bump-python-tools
tooling: Bump python tools to latest version
2 parents d882515 + 3829419 commit 2c07fc7

File tree

12 files changed

+94
-92
lines changed

12 files changed

+94
-92
lines changed

.containerversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
47
1+
48

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ docstring-min-length=10
88

99
[MESSAGES CONTROL]
1010
# Black/pylint mismatch on code formatting
11-
disable=bad-continuation, fixme, too-few-public-methods, duplicate-code, line-too-long, consider-using-f-string, too-many-locals, raise-missing-from, super-init-not-called, too-many-lines
11+
disable=fixme, too-few-public-methods, duplicate-code, line-too-long, consider-using-f-string, too-many-locals, raise-missing-from, super-init-not-called, too-many-lines, broad-exception-raised, too-many-positional-arguments
1212
good-names=i,j,tx
1313

1414
[TYPECHECK]

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ RUN rm /tmp/requirements.txt
9595

9696
# Python modules for CI
9797
RUN python3 -m pip install --upgrade \
98-
pylint==2.13.9 \
99-
pylint-protobuf==0.20.2 \
100-
black==22.3.0 \
101-
mypy==0.960 \
102-
mypy-protobuf==3.2.0
98+
pylint==3.3.7 \
99+
pylint-protobuf==0.22.0 \
100+
black==25.1.0 \
101+
mypy==1.15.0 \
102+
mypy-protobuf==3.6.0
103103

104104
# Python modules for packaging
105105
RUN python3 -m pip install --upgrade \

py/bitbox02/bitbox02/bitbox02/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
""" Library to interact with a BitBox02 device. """
14+
"""Library to interact with a BitBox02 device."""
1515

1616
from __future__ import print_function
1717
import sys

py/bitbox02/bitbox02/bitbox02/bootloader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
""" Interact with a BitBox02 bootloader. """
14+
"""Interact with a BitBox02 bootloader."""
1515

1616
import struct
1717
import typing
@@ -160,7 +160,7 @@ def show_firmware_hash_enabled(self) -> bool:
160160
"""
161161
Returns whether the bootloader will automatically show the firmware hash on boot.
162162
"""
163-
return bool(self._query(b"H\xFF")[0])
163+
return bool(self._query(b"H\xff")[0])
164164

165165
def set_show_firmware_hash(self, enable: bool) -> None:
166166
"""
@@ -233,7 +233,7 @@ def erased(self) -> bool:
233233
# We check by comparing the device reported firmware hash.
234234
# If erased, the firmware is all '\xFF'.
235235
firmware_v, _ = self.versions()
236-
empty_firmware = struct.pack("<I", firmware_v) + b"\xFF" * MAX_FIRMWARE_SIZE
236+
empty_firmware = struct.pack("<I", firmware_v) + b"\xff" * MAX_FIRMWARE_SIZE
237237
empty_firmware_hash = hashlib.sha256(hashlib.sha256(empty_firmware).digest()).digest()
238238
reported_firmware_hash, _ = self.get_hashes()
239239
return empty_firmware_hash == reported_firmware_hash

py/bitbox02/bitbox02/communication/bitbox_api_protocol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def __init__(self, need_atleast: semver.VersionInfo):
240240
class BitBoxNoiseConfig:
241241
"""Stores Functions required setup a noise connection"""
242242

243-
# pylint: disable=no-self-use,unused-argument
243+
# pylint: disable=unused-argument
244244
def show_pairing(self, code: str, device_response: Callable[[], bool]) -> bool:
245245
"""
246246
Returns True if the user confirms the pairing (both device and host).
@@ -546,6 +546,8 @@ def __init__(
546546
edition = BitBox02Edition.MULTI
547547
elif device_info["product_string"] in (BITBOX02BTC, BITBOX02PLUS_BTC):
548548
edition = BitBox02Edition.BTCONLY
549+
else:
550+
raise Exception("Invalid product string")
549551
else:
550552
version, _, edition, _, _ = self.get_info(transport)
551553

py/bitbox02/bitbox02/communication/communication.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,25 @@ class TransportLayer(Protocol):
2626
transmitting byte strings.
2727
"""
2828

29-
# pylint: disable=unused-argument,no-self-use
29+
# pylint: disable=unused-argument
3030
def write(self, data: bytes, endpoint: int, cid: int) -> None:
3131
"""Sends a frame of data to the specified endpoint"""
3232

33-
def read(self, endpoint: int, cid: int) -> bytes:
34-
...
33+
def read(self, endpoint: int, cid: int) -> bytes: ...
3534

3635
def query(self, data: bytes, endpoint: int, cid: int) -> bytes:
3736
self.write(data, endpoint, cid)
3837
return self.read(endpoint, cid)
3938

40-
def generate_cid(self) -> int:
41-
...
39+
def generate_cid(self) -> int: ...
4240

43-
def close(self) -> None:
44-
...
41+
def close(self) -> None: ...
4542

4643

4744
class PhysicalLayer(Protocol):
48-
# pylint: disable=unused-argument,no-self-use
49-
def write(self, data: bytes) -> None:
50-
...
45+
# pylint: disable=unused-argument
46+
def write(self, data: bytes) -> None: ...
5147

52-
def read(self, size: int, timeout_ms: int) -> bytes:
53-
...
48+
def read(self, size: int, timeout_ms: int) -> bytes: ...
5449

55-
def close(self) -> None:
56-
...
50+
def close(self) -> None: ...

py/bitbox02/bitbox02/communication/u2fhid/u2fhid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def write(self, data: bytes, endpoint: int, cid: int) -> None:
101101
b"\0"
102102
+ struct.pack(">IBH", cid, endpoint, data_len)
103103
+ buf
104-
+ b"\xEE" * (USB_REPORT_SIZE - 7 - len(buf))
104+
+ b"\xee" * (USB_REPORT_SIZE - 7 - len(buf))
105105
)
106106
else:
107107
# CONT frame
@@ -110,7 +110,7 @@ def write(self, data: bytes, endpoint: int, cid: int) -> None:
110110
b"\0"
111111
+ struct.pack(">IB", cid, seq)
112112
+ buf
113-
+ b"\xEE" * (USB_REPORT_SIZE - 5 - len(buf))
113+
+ b"\xee" * (USB_REPORT_SIZE - 5 - len(buf))
114114
)
115115
seq += 1
116116
idx += len(buf)

py/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Modules needed to run scripts in this directory
22
tzlocal>=1.5,<2.0
3-
# until bitbox02 is released it must be installed from py/bitbox02
3+
types-tzlocal
44
bitbox02
55
requests
6+
types-requests

py/send_message.py

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import textwrap
2828
import json
2929

30-
import requests # type: ignore
30+
import requests
3131
import hid
3232
import semver
33-
from tzlocal import get_localzone # type: ignore
33+
from tzlocal import get_localzone
3434

3535
from bitbox02 import util
3636
from bitbox02 import bitbox02
@@ -58,11 +58,11 @@ def eprint(*args: Any, **kwargs: Any) -> None:
5858

5959

6060
def ask_user(
61-
choices: Sequence[Tuple[str, Callable[[], None]]]
61+
choices: Sequence[Tuple[str, Callable[[], None]]],
6262
) -> Union[Callable[[], None], bool, None]:
6363
"""Ask user to choose one of the choices, q quits"""
6464
print("What would you like to do?")
65-
for (idx, choice) in enumerate(choices):
65+
for idx, choice in enumerate(choices):
6666
print(f"- ({idx+1}) {choice[0]}")
6767
print("- (q) Quit")
6868
ans_str = input("")
@@ -253,7 +253,7 @@ def _print_backups(self, backups: Optional[Sequence[bitbox02.Backup]] = None) ->
253253
print("No backups found.")
254254
return
255255
fmt = "%Y-%m-%d %H:%M:%S %z"
256-
for (i, (backup_id, backup_name, date)) in enumerate(backups):
256+
for i, (backup_id, backup_name, date) in enumerate(backups):
257257
date = local_timezone.localize(date)
258258
date_str = date.strftime(fmt)
259259
print(f"[{i+1}] Backup Name: {backup_name}, Time: {date_str}, ID: {backup_id}")
@@ -758,7 +758,7 @@ def _sign_btc_policy(self) -> None:
758758
bip44_account: int = 0 + HARDENED
759759
account_keypath = [48 + HARDENED, 1 + HARDENED, bip44_account, 3 + HARDENED]
760760
inputs, outputs = _btc_demo_inputs_outputs(bip44_account)
761-
for (i, inp) in enumerate(inputs):
761+
for i, inp in enumerate(inputs):
762762
inp["keypath"] = account_keypath + [0, i]
763763
inp["script_config_index"] = 0
764764
assert isinstance(outputs[0], bitbox02.BTCOutputInternal)
@@ -789,7 +789,10 @@ def _sign_btc_tx_from_raw(self) -> None:
789789

790790
def get(tx_id: str) -> Any:
791791
return requests.get(
792-
"https://api.blockchair.com/bitcoin/testnet/dashboards/transaction/{}".format(tx_id)
792+
"https://api.blockchair.com/bitcoin/testnet/dashboards/transaction/{}".format(
793+
tx_id
794+
),
795+
timeout=30,
793796
).json()["data"][tx_id]
794797

795798
tx_id = input("Paste a btc testnet tx ID: ").strip()
@@ -1711,6 +1714,9 @@ def read(self, size: int, timeout_ms: int) -> bytes:
17111714
print(f"Read from the simulator:\n{res.hex()}")
17121715
return res
17131716

1717+
def close(self) -> None:
1718+
return None
1719+
17141720
def __del__(self) -> None:
17151721
print("Simulator quit")
17161722
self.client_socket.close()
@@ -1749,67 +1755,65 @@ def connect_to_usb_bitbox(debug: bool, use_cache: bool) -> int:
17491755
except devices.NoneFoundException:
17501756
print("Neither bitbox nor bootloader found.")
17511757
return 1
1752-
else:
1753-
hid_device = hid.device()
1754-
hid_device.open_path(bootloader["path"])
1755-
bootloader_connection = bitbox02.Bootloader(u2fhid.U2FHid(hid_device), bootloader)
1756-
boot_app = SendMessageBootloader(bootloader_connection)
1757-
return boot_app.run()
1758-
else:
1758+
hid_device = hid.device()
1759+
hid_device.open_path(bootloader["path"])
1760+
bootloader_connection = bitbox02.Bootloader(u2fhid.U2FHid(hid_device), bootloader)
1761+
boot_app = SendMessageBootloader(bootloader_connection)
1762+
return boot_app.run()
17591763

1760-
def show_pairing(code: str, device_response: Callable[[], bool]) -> bool:
1761-
print("Please compare and confirm the pairing code on your BitBox02:")
1762-
print(code)
1763-
if not device_response():
1764-
return False
1765-
return input("Accept pairing? [y]/n: ").strip() != "n"
1764+
def show_pairing(code: str, device_response: Callable[[], bool]) -> bool:
1765+
print("Please compare and confirm the pairing code on your BitBox02:")
1766+
print(code)
1767+
if not device_response():
1768+
return False
1769+
return input("Accept pairing? [y]/n: ").strip() != "n"
17661770

1767-
class NoiseConfig(util.NoiseConfigUserCache):
1768-
"""NoiseConfig extends NoiseConfigUserCache"""
1771+
class NoiseConfig(util.NoiseConfigUserCache):
1772+
"""NoiseConfig extends NoiseConfigUserCache"""
17691773

1770-
def __init__(self) -> None:
1771-
super().__init__("shift/send_message")
1774+
def __init__(self) -> None:
1775+
super().__init__("shift/send_message")
17721776

1773-
def show_pairing(self, code: str, device_response: Callable[[], bool]) -> bool:
1774-
return show_pairing(code, device_response)
1777+
def show_pairing(self, code: str, device_response: Callable[[], bool]) -> bool:
1778+
return show_pairing(code, device_response)
17751779

1776-
def attestation_check(self, result: bool) -> None:
1777-
if result:
1778-
print("Device attestation PASSED")
1779-
else:
1780-
print("Device attestation FAILED")
1780+
def attestation_check(self, result: bool) -> None:
1781+
if result:
1782+
print("Device attestation PASSED")
1783+
else:
1784+
print("Device attestation FAILED")
17811785

1782-
class NoiseConfigNoCache(bitbox_api_protocol.BitBoxNoiseConfig):
1783-
"""NoiseConfig extends BitBoxNoiseConfig"""
1786+
class NoiseConfigNoCache(bitbox_api_protocol.BitBoxNoiseConfig):
1787+
"""NoiseConfig extends BitBoxNoiseConfig"""
17841788

1785-
def show_pairing(self, code: str, device_response: Callable[[], bool]) -> bool:
1786-
return show_pairing(code, device_response)
1789+
def show_pairing(self, code: str, device_response: Callable[[], bool]) -> bool:
1790+
return show_pairing(code, device_response)
17871791

1788-
def attestation_check(self, result: bool) -> None:
1789-
if result:
1790-
print("Device attestation PASSED")
1791-
else:
1792-
print("Device attestation FAILED")
1792+
def attestation_check(self, result: bool) -> None:
1793+
if result:
1794+
print("Device attestation PASSED")
1795+
else:
1796+
print("Device attestation FAILED")
17931797

1794-
if use_cache:
1795-
config: bitbox_api_protocol.BitBoxNoiseConfig = NoiseConfig()
1796-
else:
1797-
config = NoiseConfigNoCache()
1798+
if use_cache:
1799+
config: bitbox_api_protocol.BitBoxNoiseConfig = NoiseConfig()
1800+
else:
1801+
config = NoiseConfigNoCache()
17981802

1799-
hid_device = hid.device()
1800-
hid_device.open_path(bitbox["path"])
1801-
bitbox_connection = bitbox02.BitBox02(
1802-
transport=u2fhid.U2FHid(hid_device), device_info=bitbox, noise_config=config
1803-
)
1804-
try:
1805-
bitbox_connection.check_min_version()
1806-
except FirmwareVersionOutdatedException as exc:
1807-
print("WARNING: ", exc)
1803+
hid_device = hid.device()
1804+
hid_device.open_path(bitbox["path"])
1805+
bitbox_connection = bitbox02.BitBox02(
1806+
transport=u2fhid.U2FHid(hid_device), device_info=bitbox, noise_config=config
1807+
)
1808+
try:
1809+
bitbox_connection.check_min_version()
1810+
except FirmwareVersionOutdatedException as exc:
1811+
print("WARNING: ", exc)
18081812

1809-
if debug:
1810-
print("Device Info:")
1811-
pprint.pprint(bitbox)
1812-
return SendMessage(bitbox_connection, debug).run()
1813+
if debug:
1814+
print("Device Info:")
1815+
pprint.pprint(bitbox)
1816+
return SendMessage(bitbox_connection, debug).run()
18131817

18141818

18151819
def main() -> int:

0 commit comments

Comments
 (0)