%global _empty_manifest_terminate_build 0 Name: python-ledgercomm Version: 1.2.0 Release: 1 Summary: Library to communicate with Ledger Nano S/X and Speculos License: MIT License URL: https://github.com/LedgerHQ/ledgercomm Source0: https://mirrors.aliyun.com/pypi/web/packages/2e/63/ded336a4a8d84603bcce5799e2b6ff8ff9f12f5bfb777a3443fde7f4fca3/ledgercomm-1.2.0.tar.gz BuildArch: noarch Requires: python3-hidapi %description # LedgerCOMM ## Overview Python library to send and receive [APDU](https://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit) through HID or TCP socket. It can be used with a Ledger Nano S/X or with the [Speculos](https://github.com/LedgerHQ/speculos) emulator. ## Install If you just want to communicate through TCP socket, there is no dependency ```bash $ pip install ledgercomm ``` otherwise, [hidapi](https://github.com/trezor/cython-hidapi) must be installed as an extra dependency like this ```bash $ pip install ledgercomm[hid] ``` ## Getting started ### Library ```python 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` ```bash $ 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 ```bash $ 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 ```text # this line won't be send if you've the right STARTSWITH condition => E003000000 # another APDU to send => E004000000 ``` then ```bash $ ledgercomm-send --startswith "=>" file apdus.txt ``` %package -n python3-ledgercomm Summary: Library to communicate with Ledger Nano S/X and Speculos Provides: python-ledgercomm BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-ledgercomm # LedgerCOMM ## Overview Python library to send and receive [APDU](https://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit) through HID or TCP socket. It can be used with a Ledger Nano S/X or with the [Speculos](https://github.com/LedgerHQ/speculos) emulator. ## Install If you just want to communicate through TCP socket, there is no dependency ```bash $ pip install ledgercomm ``` otherwise, [hidapi](https://github.com/trezor/cython-hidapi) must be installed as an extra dependency like this ```bash $ pip install ledgercomm[hid] ``` ## Getting started ### Library ```python 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` ```bash $ 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 ```bash $ 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 ```text # this line won't be send if you've the right STARTSWITH condition => E003000000 # another APDU to send => E004000000 ``` then ```bash $ ledgercomm-send --startswith "=>" file apdus.txt ``` %package help Summary: Development documents and examples for ledgercomm Provides: python3-ledgercomm-doc %description help # LedgerCOMM ## Overview Python library to send and receive [APDU](https://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit) through HID or TCP socket. It can be used with a Ledger Nano S/X or with the [Speculos](https://github.com/LedgerHQ/speculos) emulator. ## Install If you just want to communicate through TCP socket, there is no dependency ```bash $ pip install ledgercomm ``` otherwise, [hidapi](https://github.com/trezor/cython-hidapi) must be installed as an extra dependency like this ```bash $ pip install ledgercomm[hid] ``` ## Getting started ### Library ```python 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` ```bash $ 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 ```bash $ 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 ```text # this line won't be send if you've the right STARTSWITH condition => E003000000 # another APDU to send => E004000000 ``` then ```bash $ ledgercomm-send --startswith "=>" file apdus.txt ``` %prep %autosetup -n ledgercomm-1.2.0 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-ledgercomm -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Fri Jun 09 2023 Python_Bot - 1.2.0-1 - Package Spec generated