Skip to content

Commit

Permalink
flake8 pass
Browse files Browse the repository at this point in the history
  • Loading branch information
bargst committed Jun 12, 2018
1 parent 002dbd0 commit ccc3006
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions eth_account/signers/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _path_to_bytes(self, path):
elements = path.split('/')[1:]
depth = len(elements)

result = bytes([depth]) # Number of BIP 32 derivations to perform (max 10)
result = bytes([depth]) # Number of BIP 32 derivations to perform (max 10)

for derivation_index in elements:
# For each derivation index in the path check if it is hardened
Expand Down Expand Up @@ -113,16 +113,17 @@ def get_address(self, account_id):
'''
bip32_path = self._path_to_bytes(self.path_prefix + str(account_id))

apdu = bytes.fromhex('e0020000') # https://github.com/LedgerHQ/blue-app-eth/blob/master/doc/ethapp.asc#get-eth-public-address
# https://github.com/LedgerHQ/blue-app-eth/blob/master/doc/ethapp.asc#get-eth-public-address
apdu = bytes.fromhex('e0020000')
apdu += bytes([len(bip32_path)])
apdu += bip32_path

result = self._send_to_device(apdu)

# Parse result
offset = 1 + result[0]
address = result[offset + 1 : offset + 1 + result[offset]]
address = address.decode() # Use decode() to convert from bytearray
address = result[offset + 1: offset + 1 + result[offset]]
address = address.decode() # Use decode() to convert from bytearray

return eth_utils.to_normalized_address(address)

Expand All @@ -136,15 +137,18 @@ def get_account_id(self, address, search_limit=20, search_account_id=0):

for account_id in itertools.count(start=search_account_id):
if account_id > search_limit:
raise Exception(f'Address {address} not found (search_limit={search_limit}, search_account_id={search_account_id})')
raise Exception(f'Address {address} not found' +
f'(search_limit={search_limit}, ' +
f'search_account_id={search_account_id})')
if address == self.get_address(account_id):
return account_id

def list(self, limit=5, page=0):
'''
List Ethereum HD wallet adrress of the ledger device
'''
return list(map(lambda account_id: self.get_address(account_id), range(page*limit, (page+1)*limit)))
return list(map(lambda account_id: self.get_address(account_id),
range(page * limit, (page + 1) * limit)))

def signHash(self, message_hash):
'''
Expand All @@ -162,7 +166,8 @@ def signTransaction(self, transaction_dict):
unsigned_transaction = serializable_unsigned_transaction_from_dict(transaction_dict)
rlp_encoded_tx = rlp.encode(unsigned_transaction)

apdu = bytes.fromhex('e0040000') # https://github.com/LedgerHQ/blue-app-eth/blob/master/doc/ethapp.asc#sign-eth-transaction
# https://github.com/LedgerHQ/blue-app-eth/blob/master/doc/ethapp.asc#sign-eth-transaction
apdu = bytes.fromhex('e0040000')
apdu += bytes([len(bip32_path) + len(rlp_encoded_tx)])
apdu += bip32_path
apdu += rlp_encoded_tx
Expand Down

0 comments on commit ccc3006

Please sign in to comment.