Library to interface with ledger-app-eth on Ledger hardware wallets
Project description
ledger-eth-lib
This is a WIP. Consider it alpha
This is a library to interact with ledger-app-eth, the Ethereum app for the Ledger hardware wallets. It's goal is to make interfacing with the Ledger nice and simple with well known Ethereum+Python tools.
NOTE: Tested to work on Ledger Nano S and Nano X. Will probalby work with Ledger Blue
Web3.py Integration
ledger-eth-lib provides a Web3.py middleware. It will automatically intercept the relevant JSON-RPC calls and respond with data from your Ledger device.
from web3.auto import w3
from ledgereth.web3 import LedgerSignerMiddleware
w3.middleware_onion.add(LedgerSignerMiddleware)
Intercepted JSON-RPC methods:
eth_sendTransaction
eth_accounts
Quickstart
Get Accounts
Fetch the availible accounts (currently only default).
from ledgereth import get_accounts
accounts = get_accounts()
my_account = accounts[0]
Create and Sign a Transaction
Create a transaction object and sign it.
from ledgereth import create_transaction
tx = create_transaction(
'0xb78f53524ae9d465279e7c3495f71d5db2419e13', # to
'0x4dae53ee778a324bd317bd270d6227406b6bd4ec', # from
int(1e18), # value
int(1e5), # gas limit
int(1e9), # gas price
1 # nonce
)
signature = '0x{}{}{}'.format(
hex(tx.v)[2:],
hex(tx.r)[2:],
hex(tx.s)[2:],
)
Sign an Existing Transaction Object
Sign a Transaction
object from pyethereum(or similar RLP serializable):
from ledgereth import sign_transaction
tx = sign_transaction(tx)
signature = '0x{}{}{}'.format(
hex(tx.v)[2:],
hex(tx.r)[2:],
hex(tx.s)[2:],
)
API
get_accounts(dongle: Any = None)
Fetch a List
of accounts.
NOTE: This will currently only return the default/primary account from the device.
sign_transaction(tx: Serializable, dongle: Any = None)
Sign a rlp.Serializable
transaction.
create_transaction(to: bytes, sender: bytes, value: int, gas: int, gas_price: int, nonce: int, data: bytes, dongle: Any = None)
Create and sign an rlp.Serializable
transaction from provided params
TODO
- Add fake dongle support to pytest suite so tests can be run without a real Ledger and human interaction
- Fill out tests
- Add messaging signing support
- Add support for multiple accounts(different derivations?)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ledgereth-0.1.1.tar.gz
.
File metadata
- Download URL: ledgereth-0.1.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1649bf139167fab42c05a29e0e26519a2d7cf29b5486cd842a0a149e84a8a90a |
|
MD5 | b7a1ed63d1963e4e3aca487e6466af86 |
|
BLAKE2b-256 | 3ceaf60c61b04860bd3371d7ad42f2f936149f964d356768da573d90aecf2be6 |
File details
Details for the file ledgereth-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: ledgereth-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eed8b9b7ec5e3bb7e8f9594e128e2c8ecdb9f35bb45c2a1221410d746d12a57 |
|
MD5 | 5a9a502854f7c6d7a266863b5c18b413 |
|
BLAKE2b-256 | e3c0f14875ec561f38a5d4385c219d750c355d09413cdf6b751a263ee78a9fed |