Skip to content

Commit c2504ef

Browse files
authored
Merge pull request #46 from mikeshultz/cleaning
fix: minor docs and type fixes
2 parents 4b3a1db + 3829e3f commit c2504ef

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

DEVELOPMENT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Docs
44

5-
A goo dway to work on docs is to use `sphinx-autobuild` that will build the docs and start a local Web server that will auto-reload on save.
5+
A good way to work on docs is to use `sphinx-autobuild` that will build the docs and start a local Web server that will auto-reload on save.
66

77
sphinx-autobuild --watch ledgereth/ docs/ build/docs/
88

ledgereth/comms.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515

1616
class LedgerCommands:
17-
"""APDU commands for communication with ledger-app-eth. Tested only on a Ledger Nano S.
17+
"""APDU commands for communication with Ledger's app-ethereum. Tested on
18+
Ledger Nano S and Nano X.
1819
1920
See `ledger-app-eth<https://github.com/LedgerHQ/ledger-app-eth/blob/master/doc/ethapp.asc>`_
2021
documentation.
@@ -86,7 +87,7 @@ def get(name: str) -> bytes:
8687

8788
@staticmethod
8889
def get_with_data(
89-
name: str, data: bytes, Lc: bytes = None, Le: bytes = None
90+
name: str, data: bytes, Lc: Optional[bytes] = None, Le: Optional[bytes] = None
9091
) -> bytes:
9192
if not hasattr(LedgerCommands, name):
9293
raise ValueError("Command not available")
@@ -109,7 +110,11 @@ def dongle_send(dongle: Dongle, command_string: str) -> bytes:
109110

110111

111112
def dongle_send_data(
112-
dongle: Dongle, command_string: str, data: bytes, Lc: bytes = None, Le: bytes = None
113+
dongle: Dongle,
114+
command_string: str,
115+
data: bytes,
116+
Lc: Optional[bytes] = None,
117+
Le: Optional[bytes] = None,
113118
) -> bytes:
114119
"""Send a command with data to the dongle"""
115120
hex_command = LedgerCommands.get_with_data(command_string, data, Lc=Lc, Le=Le)

ledgereth/constants.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
2-
from typing import Any, Dict, Type
3-
4-
from eth_utils import remove_0x_prefix
2+
from typing import Any, Dict
53

64

75
def getenvint(key, default=0):
@@ -31,14 +29,14 @@ def getenvint(key, default=0):
3129
if LEGACY_ACCOUNTS:
3230
DEFAULT_PATH_STRING = "44'/60'/0'/0"
3331
DEFAULT_PATH_ENCODED = b"\x80\x00\x00,\x80\x00\x00<\x80\x00\x00\x00\x00\x00\x00\x00"
34-
DEFAULT_PATH = remove_0x_prefix(DEFAULT_PATH_ENCODED.hex())
32+
DEFAULT_PATH = DEFAULT_PATH_ENCODED.hex()
3533
VRS_RETURN_LENGTH = int(65).to_bytes(1, "big")
3634

3735
# Data size expected from Ledger
3836
DATA_CHUNK_SIZE = 255
3937

4038
# Default "zero" values in EVM/Solidity
41-
DEFAULTS: Dict[Type, Any] = {
39+
DEFAULTS: Dict[type, Any] = {
4240
int: 0,
4341
bytes: b"",
4442
}

ledgereth/messages.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def sign_message(
2525
app on the Ledger device according to `EIP-191`_.
2626
2727
:param message: (:code:`str|bytes`) - A bit of text to sign
28-
:param sender_path: (:code:`str`) - HID derivation path for the account to
28+
:param sender_path: (:code:`str`) - HD derivation path for the account to
2929
sign with.
3030
:param dongle: (:class:`ledgerblue.Dongle.Dongle`) - The Web3 instance to use
3131
:return: :class:`ledgereth.objects.SignedMessage`
@@ -101,7 +101,7 @@ def sign_typed_data_draft(
101101
102102
:param domain_hash: (:code:`str`) - Hash of the EIP-712 domain
103103
:param message_hash: (:code:`str`) - Hash of the message
104-
:param sender_path: (:code:`str`) - HID derivation path for the account to
104+
:param sender_path: (:code:`str`) - HD derivation path for the account to
105105
sign with. Defaults to first account in the derivation path.
106106
:param dongle: (:class:`ledgerblue.Dongle.Dongle`) - The Dongle instance to
107107
use to communicate with the Ledger device

ledgereth/objects.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def __init__(
8080
INS: bytes,
8181
P1: bytes,
8282
P2: bytes,
83-
Lc: bytes = None,
84-
Le: bytes = None,
85-
data: bytes = None,
83+
Lc: Optional[bytes] = None,
84+
Le: Optional[bytes] = None,
85+
data: Optional[bytes] = None,
8686
):
8787
if not (
8888
is_bytes(CLA)
@@ -103,7 +103,7 @@ def __init__(
103103
self.Le = Le
104104
self.data = data
105105

106-
def set_data(self, data: bytes, Lc: bytes = None) -> None:
106+
def set_data(self, data: bytes, Lc: Optional[bytes] = None) -> None:
107107
"""Set the command data and its length
108108
109109
:param data: (:class:`bytes`) - The raw ``bytes`` data. This should not
@@ -243,8 +243,8 @@ class Transaction(SerializableTransaction):
243243
244244
.. note:: A chain_id is set by default (``1``). It is not required to be
245245
a valid legacy transaction, but without it your transaction is
246-
suceptible to replay attack. If for some reason you absolutely do not want it in your
247-
tx, set it to ``None``.
246+
suceptible to replay attack. If for some reason you absolutely do not
247+
want it in your tx, set it to ``None``.
248248
249249
.. _`EIP-155`: https://eips.ethereum.org/EIPS/eip-155
250250
"""

ledgereth/utils.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,27 @@ def coerce_access_list(access_list):
191191
return access_list
192192

193193

194-
def coerce_list_types(types: List[Type], to_coerce: List[Any]) -> List[Any]:
194+
def coerce_list_types(
195+
types: List[Optional[type]], to_coerce: List[Union[Any, None]]
196+
) -> List[Any]:
195197
"""Coerce types of a list to given types in order"""
196198

197199
for i, v in enumerate(to_coerce):
198200
# SKIP!
199201
if types[i] is None:
200202
continue
201203

204+
# Only way to get mypy to chill was to assign to its own var
205+
this_type = types[i]
206+
assert this_type is not None
207+
202208
# Some things don't transalate, like b'' being 0
203209
if not v:
204-
to_coerce[i] = DEFAULTS[types[i]]
210+
to_coerce[i] = DEFAULTS[this_type]
205211
else:
206212
if types[i] in COERCERS:
207-
to_coerce[i] = COERCERS[types[i]](v)
213+
to_coerce[i] = COERCERS[this_type](v)
208214
else:
209-
to_coerce[i] = types[i](v)
215+
to_coerce[i] = this_type(v)
210216

211217
return to_coerce

0 commit comments

Comments
 (0)