LedgerCOMM
Overview
Python library to send and receive APDU through HID or TCP socket. It can be used with a Ledger Nano S/X or with the Speculos emulator.
Install
If you just want to communicate through TCP socket, there is no dependency
$ pip install ledgercomm
otherwise, hidapi must be installed as an extra dependency like this
$ pip install ledgercomm[hid]
Getting started
Library
from ledgercomm import Transport
# Nano S/X using HID interface
transport = Transport(interface="hid", debug=True)
# or Speculos through TCP socket
transport = Transport(interface="tcp", server="127.0.0.1", port=9999, debug=True)
#
# send/recv APDUs
#
# send method for structured APDUs
transport.send(cla=0xe0, ins=0x03, p1=0, p2=0, cdata=b"") # send b"\xe0\x03\x00\x00\x00"
# or send_raw method for hexadecimal string
transport.send_raw("E003000000") # send b"\xe0\x03\x00\x00\x00"
# or with bytes type
transport.send_raw(b"\xe0\x03\x00\x00\x00")
# Waiting for a response (blocking IO)
sw, response = transport.recv() # type: int, bytes
#
# exchange APDUs (one time send/recv)
#
# exchange method for structured APDUs
sw, response = transport.exchange(cla=0xe0, ins=0x03, p1=0, p2=0, cdata=b"") # send b"\xe0\x03\x00\x00\x00"
# or exchange_raw method for hexadecimal string
sw, reponse = transport.exchange_raw("E003000000") # send b"\xe0\x03\x00\x00\x00"
# or with bytes type
sw, response = transport.exchange_raw(b"\xe0\x03\x00\x00\x00")
CLI
Usage
When installed, ledgercomm provides a CLI tool named ledgercomm-send
$ ledgercomm-send --help
usage: ledgercomm-send [-h] [--hid] [--server SERVER] [--port PORT] [--startswith STARTSWITH]
{file,stdin,log} ...
positional arguments:
{file,stdin,log} sub-command help
file send APDUs from file
stdin send APDUs from stdin
log send APDUs from Ledger Live log file
optional arguments:
-h, --help show this help message and exit
--hid Use HID instead of TCP client
--server SERVER IP server of the TCP client (default: 127.0.0.1)
--port PORT Port of the TCP client (default: 9999)
--startswith STARTSWITH
Only send APDUs starting with STARTSWITH (default: None)
Example
If Speculos is launched with default parameters or your Nano S/X is plugged with correct udev rules, you can send APDUs from stdin
$ echo "E003000000" | ledgercomm-send stdin # Speculos
$ echo "E003000000" | ledgercomm-send --hid stdin # Nano S/X
Or you can replay APDUs using the following text file named apdus.txt with some condition
# this line won't be send if you've the right STARTSWITH condition
=> E003000000
# another APDU to send
=> E004000000
then
$ ledgercomm-send --startswith "=>" file apdus.txt
Metadata
Release files for ledgercomm 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ledgercomm-1.2.1.tar.gz | 14.2 kB | Without provenance | Details for ledgercomm-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ledgercomm-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for ledgercomm-1.2.1-py3-none-any.whl |
Total release size: 26.2 kB
Release files / ledgercomm-1.2.1.tar.gz
| Download URL | ledgercomm-1.2.1.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
015cfc05f16b8c59f8cc1d9fc0b8935923f1fcc3806d33eeb6b0e055b44f5a91
|
|
BLAKE2b-256 checksum How to use checksums |
938b31d9445c092d5f44ba22c26452bd235fa1b2b3b15fd21e98e9c5cbf170ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / ledgercomm-1.2.1-py3-none-any.whl
| Download URL | ledgercomm-1.2.1-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ffef5703355b8ec7b73bca325f70288f4d0dafcb299c09833de9c197fb6dd34
|
|
BLAKE2b-256 checksum How to use checksums |
c607633e1da1b002822d18614e7faf924bc7c3064a11b1879cc0fd4a153d727c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for ledgercomm 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.