Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: align repo with trezor #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions ape_ledger/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@
from ape.convert import to_address
from ape.types import AddressType, MessageSignature, TransactionSignature
from eth_account.messages import SignableMessage
from hexbytes import HexBytes

from ape_ledger.client import LedgerEthereumAccountClient, connect_to_ethereum_account
from ape_ledger.exceptions import LedgerSigningError
from ape_ledger.hdpath import HDAccountPath


def _extract_version(msg: SignableMessage) -> bytes:
if isinstance(msg.version, HexBytes):
return msg.version.hex().encode()

return msg.version


class AccountContainer(AccountContainerAPI):
_usb_device = None

Expand Down Expand Up @@ -84,19 +76,20 @@ def _client(self) -> LedgerEthereumAccountClient:
return self._account_client

def sign_message(self, msg: SignableMessage) -> Optional[MessageSignature]:
version = _extract_version(msg)
version = msg.version

if version == b"E":
vrs = self._client.sign_personal_message(msg.body)
elif version == b"0x01":
vrs = self._client.sign_typed_data(msg.header, msg.body)
signed_msg = self._client.sign_personal_message(msg.body)
elif version == b"\x01":
signed_msg = self._client.sign_typed_data(msg.header, msg.body)
else:
raise LedgerSigningError(
f"Unsupported message-signing specification, (version={version!r})"
)

return MessageSignature(*vrs) # type: ignore
return MessageSignature(*signed_msg) # type: ignore

def sign_transaction(self, txn: TransactionAPI) -> Optional[TransactionSignature]:
vrs = self._client.sign_transaction(txn.as_dict())
return TransactionSignature(*vrs) # type: ignore
signed_txn = self._client.sign_transaction(txn.as_dict())

return TransactionSignature(*signed_txn) # type: ignore
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ markers = "fuzzing: Run Hypothesis fuzz test suite"
line_length = 100
force_grid_wrap = 0
include_trailing_comma = true
known_third_party = ["ape", "click", "eip712", "eth_account", "eth_typing", "eth_utils", "hexbytes", "hid", "pytest", "rlp", "setuptools"]
known_third_party = ["ape", "click", "eip712", "eth_account", "eth_typing", "eth_utils", "hid", "pytest", "rlp", "setuptools"]
known_first_party = ["ape_ledger", "conftest"]
multi_line_output = 3
use_parentheses = true