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

Make dependencies for Ledger support optional #1474

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
14 changes: 7 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

- name: Check poetry.lock
run: |
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

# ====================== CONTRACTS v2 ====================== #
- name: Cache contracts v2
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

# ====================== SETUP DEVNET ====================== #

Expand Down Expand Up @@ -287,7 +287,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

# ====================== SETUP DEVNET ====================== #

Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

# ====================== RUN TESTS ====================== #

Expand Down Expand Up @@ -436,7 +436,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

# ====================== SETUP DEVNET ====================== #

Expand Down Expand Up @@ -503,7 +503,7 @@ jobs:

- name: Install dependencies
run: |
poetry install
poetry install -E ledger

# ====================== SETUP DEVNET ====================== #

Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
jobs:
pre_install:
- pip install poetry
- poetry export -f requirements.txt --output requirements.txt --without-hashes --extras docs
- poetry export -f requirements.txt --output requirements.txt --without-hashes -E docs -E ledger

sphinx:
configuration: docs/conf.py
Expand Down
6 changes: 6 additions & 0 deletions docs/api/signer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ KeyPair
LedgerSigner
------------

To use LedgerSigner, you need to install starknetpy with `ledger` extra like this:

.. code-block:: bash

poetry add starknet_py[ledger]

.. py:module:: starknet_py.net.signer.ledger_signer

.. autoclass:: LedgerSigner
Expand Down
4 changes: 2 additions & 2 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Dependencies

.. code-block:: bash

poetry install
poetry install -E ledger

Contracts
^^^^^^^^^
Expand All @@ -64,7 +64,7 @@ Documentation
.. code-block:: bash

# Install additional dependencies for docs
poetry install -E docs
poetry install -E ledger -E docs

# Generate HTML documentation
poe docs_create
Expand Down
1,076 changes: 577 additions & 499 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ furo = { version = "^2024.5.6", optional = true }
pycryptodome = "^3.17"
crypto-cpp-py = "1.4.4"
eth-keyfile = "^0.8.1"
ledgerwallet = "^0.5.0"
bip-utils = "^2.9.3"
ledgerwallet = { version = "^0.5.0", optional = true }
bip-utils = { version = "^2.9.3", optional = true }

[tool.poetry.extras]
docs = ["sphinx", "enum-tools", "furo"]
ledger = ["ledgerwallet", "bip-utils"]

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
Expand Down
26 changes: 22 additions & 4 deletions starknet_py/net/signer/ledger_signer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from typing import List

from bip_utils import Bip32KeyIndex, Bip32Path, Bip32Utils
from ledgerwallet.client import LedgerClient
from typing import TYPE_CHECKING, List

from starknet_py.constants import (
EIP_2645_PATH_LENGTH,
Expand All @@ -17,6 +14,27 @@
from starknet_py.utils.typed_data import TypedData


class LateException:
def __init__(self, exc: Exception):
self.exc = exc

def __getattr__(self, item):
raise self.exc

def __call__(self, *args, **kwargs):
self.__getattr__("exc")


try:
from bip_utils import Bip32KeyIndex, Bip32Path, Bip32Utils
from ledgerwallet.client import LedgerClient
except ImportError as e:
if TYPE_CHECKING:
raise
dummy = LateException(e)
Bip32KeyIndex, Bip32Path, Bip32Utils, LedgerClient = dummy, dummy, dummy, dummy


class LedgerStarknetApp:
def __init__(self):
self.client: LedgerClient = LedgerClient(cla=STARKNET_CLA)
Expand Down
Loading