Skip to content

Commit

Permalink
fixup! Feature: Ledger wallets could not sign using ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Aug 23, 2023
1 parent 91e78ea commit 0d7cd5e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,29 @@ or
```shell
$ python setup.py develop
```

## Usage with LedgerHQ hardware

The SDK supports signatures using [app-ethereum](https://github.com/LedgerHQ/app-ethereum),
the Ethereum app for the Ledger hardware wallets.

This has been tested successfully on Linux (amd64).
Let us know if it works for you on other operating systems.

Using a Ledger device on Linux requires root access or the setup of udev rules.

### Debian / Ubuntu

Install [ledger-wallets-udev](https://packages.debian.org/bookworm/ledger-wallets-udev).

`sudo apt-get install ledger-wallets-udev`

### On NixOS

Configure `hardware.ledger.enable = true`.

### Other Linux systems

See https://github.com/LedgerHQ/udev-rules


18 changes: 16 additions & 2 deletions src/aleph/sdk/wallets/ledger/ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ class LedgerETHAccount(BaseAccount):
_account: LedgerAccount
_device: Dongle

def __init__(self, account: LedgerAccount, device: Optional[Dongle]):
def __init__(self, account: LedgerAccount, device: Dongle):
"""Initialize an aleph.im account instance that relies on a LedgerHQ
device and the Ethereum Ledger application for signatures.
See the static methods `self.from_address(...)` and `self.from_path(...)`
for an easier method of instantiation.
"""
self._account = account
self._device = device or init_dongle()
self._device = device

@staticmethod
def from_address(
address: str, device: Optional[Dongle] = None
) -> Optional[LedgerETHAccount]:
"""Initialize an aleph.im account from a LedgerHQ device from
a known wallet address.
"""
device = device or init_dongle()
account = find_account(address=address, dongle=device, count=5)
return LedgerETHAccount(
Expand All @@ -37,6 +46,8 @@ def from_address(

@staticmethod
def from_path(path: str, device: Optional[Dongle] = None) -> LedgerETHAccount:
"""Initialize an aleph.im account from a LedgerHQ device from
a known wallet account path."""
device = device or init_dongle()
account = get_account_by_path(path_string=path, dongle=device)
return LedgerETHAccount(
Expand All @@ -61,6 +72,9 @@ def get_address(self) -> str:
return self._account.address

def get_public_key(self) -> str:
"""Obtaining the public key is not supported by the ledgereth library
we use, and may not be supported by LedgerHQ devices at all.
"""
raise NotImplementedError()


Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_wallet_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ async def test_ledger_eth_account():
signed["signature"], signed["sender"], get_verification_buffer(signed)
)

# Obtaining the public key is not supported (yet ?) on hardware wallets.
with pytest.raises(NotImplementedError):
account.get_public_key()

0 comments on commit 0d7cd5e

Please sign in to comment.