Skip to main content

Pysatochip

Licence: LGPL v3 Author: Toporin Language: Python (>= 3.6) Homepage: https://github.com/Toporin/pysatochip

Introduction

The Pysatochip library allows to integrate the Satochip Hardware Wallet with a client wallet such as electrum. To use it, you need a device with the Satochip javacard applet installed (see https://github.com/Toporin/SatochipApplet). If the wallet is not intialized yet, the wallet can perform the setup (you only need to do this once). During setup, a seed is created: this seed allows you to recover your wallet at anytime, so make sure to BACKUP THE SEED SECURELY! During setup, a PIN code is also created: this PIN allows to unlock th device to access your funds. If you try too many wrong PIN, your device will be locked indefinitely (it is 'bricked'). If you loose your PIN or brick your device, you can only recover your funds with the seed backup.

The Satochip wallet is currently in Beta, use with caution! In this phase, it is strongly recommended to use the software on the Bitcoin testnet first. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Remark: Pysatochip uses Python 3.x. In case of error, check first that you are not trying to run with Python 2.x or with Python 2.x libraries.

Satochip 2-Factor-Authentication (2FA)

Satochip-2FA is an optional feature that allows to use 2-Factor-Authentication in conjonction with the Satochip hardware wallet. When enabled, transaction requests are sent to an app on a second device for approval before signing them with the Satochip. For security, once enabled, the 2FA can only be disabled when the seed is reset. Be sure to keep a copy of the 2FA key in a safe location.

​When enabled, a secret key is shared via a qr-code between the satochip and a second device (currently, only Android). The app then regularly polls the Electrum server for new transaction proposals. These transaction candidates are then parsed and displayed on the second device. If approved, a cryptographic code is sent back to securely and uniquely approve the transaction so that the satochip can sign it.

Installing this Module

This module is available for download on PyPy with the command pip3 install pysatochip.

You can install this module on your system with the command python setup.py install.

To use the Command Line Interface, you need to install additional dependencies, use this command instead: pip install "pysatochip[CLI]" or pip install -e ".[CLI]" (local install).

Cryptographic backend

All operations involving a private key (the card secure channel's ECDH key exchange, and signing) run on a side-channel-hardened implementation. pysatochip picks one automatically:

  1. cryptography (pyca/OpenSSL) — the default, installed as a normal dependency.
  2. libsecp256k1 through embit — used when cryptography is unavailable, which is typically the case on embedded builds such as seedsigner-os. Install it with pip install "pysatochip[embedded]".

If neither is present, pysatochip raises an error on any private-key operation rather than falling back to a vulnerable implementation; signature verification continues to work. The pure-python ecdsa package is no longer used or required, as it is affected by CVE-2024-23342 — see issue #8.

Command Line Interface

Once you have installed the module, you can access its functionality through a command line client satochip-cli.

There are a wide range of available commands, each with their own relevant options. The best way to find these is with the --help argument. (satochip-cli --help)

There are also some general tools, such as those required to decrypt encrypted Seedkeeper JSON backups. (These can be accessed either standalone or via the module)

Card Authenticity Check

Use the common-verify-authenticity command to verify that the connected card was issued by Satochip:

satochip-cli common-verify-authenticity

By default the command relies on OpenSSL for certificate validation. If OpenSSL is not available, it falls back to a pure Python implementation using pycryptodomex. You can force a specific backend with the --backend option, choosing between auto, openssl, or pycryptodomex:

satochip-cli common-verify-authenticity --backend pycryptodomex

More details about the satochip-cli here.

Running from Source

If you don't want to install the pysatochip module, you can also run a number of tools direcly from the repository folder.

Command Line Tool: python satochip_cli.py

SatoChip Hardware Test python test_satochip.py

SeedKeeper Hardware Test python test_seedkeeper.py

Running the Tests

The suite in tests/ needs no hardware and runs in a few seconds:

python tests/run_all.py

Or with stdlib discovery, from the repository root:

python -m unittest discover -s tests -t .

To narrow things down, any test file can be run directly, and you can select a single class or method:

python tests/test_ec_backend.py
python tests/test_ec_backend.py TestECDH
python tests/test_ec_backend.py TestECDH.test_shared_secret_matches_frozen_vector
File Covers
test_ec_backend.py ECDH, key derivation, signing, verification and public key recovery, run against every available backend
test_ec_math.py Curve arithmetic, signature encoding, DER strictness
test_ecc.py The ECPubkey / ECPrivkey public API
test_secure_channel.py The ECDH handshake and AES layer, against a simulated applet
test_certificate_validator.py Both legs of the certificate chain, including the shipped CA certificates
test_backend_scenarios.py Whole-environment checks with dependencies deliberately made unimportable

Backend coverage

Most tests run once per available backend, so what gets exercised depends on what is installed. With only cryptography you will see OK (skipped=11): the libsecp256k1 and cross-backend tests skip themselves. Install the optional backend to cover both:

pip install "pysatochip[embedded]"

test_backend_scenarios.py covers the single-backend cases either way, by blocking imports in a subprocess. It is what verifies that pysatochip still works on a build with neither cryptography nor pyOpenSSL available, and that a private-key operation fails loudly when no hardened backend is present.

Regression vectors

tests/vectors.py holds secp256k1 values captured from the pre-0.18.0 implementation. ECDH_SHARED_X in particular pins the card secure-channel wire format: the applet derives the same shared secret on its side, so if that value ever changes, every Satochip / SeedKeeper / Satodime session breaks. Treat a failure there as a compatibility break rather than a broken test.

tests/_gen_vectors.py records how those vectors were produced, against the old ecdsa implementation. It refuses to run on the current tree, because signing is no longer deterministic here and it would emit signature values that do not match the ones being pinned. To audit a vector, check out the previous release instead:

git checkout v0.17.4 && pip install ecdsa && python tests/_gen_vectors.py

Hardware tests

The tests in the repository root are separate and need a card in a reader, ideally a non-initialized one. They are not part of run_all.py:

python test_satochip.py
python test_seedkeeper.py

test_satochip_musig2.py additionally requires a debug build of the applet.

Development version (Windows)

Install the latest python 3.6 release from https://www.python.org (https://www.python.org/downloads/release/python-368/) (Caution: installing another release than 3.6 may cause incompatibility issues with pyscard)

Clone or download the code from GitHub.

Install pyscard from https://pyscard.sourceforge.io/ Pyscard is required to connect to the smartcard::

python -m pip install pyscard

In case of error message, you may also install pyscard from the installer: Download the .whl files from https://sourceforge.net/projects/pyscard/files/pyscard/pyscard%201.9.7/ and run::

python -m pip install pyscard-1.9.7-cp36-cp36m-win_amd64.whl

Development version (Ubuntu)

Check out the code from GitHub::

git clone git://github.com/Toporin/pysatochip.git
cd pysatochip

Install pyscard (https://pyscard.sourceforge.io/) Pyscard is required to connect to the smartcard:: sudo apt-get install pcscd sudo apt-get install python3-pyscard (For alternatives, see https://github.com/LudovicRousseau/pyscard/blob/master/INSTALL.md for more detailed installation instructions)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysatochip-0.18.0.tar.gz (325.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysatochip-0.18.0-py3-none-any.whl (144.7 kB view details)

Uploaded Python 3

File details

Details for the file pysatochip-0.18.0.tar.gz.

File metadata

  • Download URL: pysatochip-0.18.0.tar.gz
  • Upload date:
  • Size: 325.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pysatochip-0.18.0.tar.gz
Algorithm Hash digest
SHA256 b8903475eaa6b3f06ea8824a474922c1abe060c9f00a09c037840d096f5c53a0
MD5 b3c8c307794d4f754869f243f7bf2b49
BLAKE2b-256 f672455821a4bed60fa53ddd7348d5b2be0e9e228869eaf7655b4da9117cb6bb

See more details on using hashes here.

File details

Details for the file pysatochip-0.18.0-py3-none-any.whl.

File metadata

  • Download URL: pysatochip-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 144.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pysatochip-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d54df40a0b9d365d425fd721d303c0d896c42b08427df60fffb19dd6132fe41
MD5 b5e907065336ec7a263d5cf075040764
BLAKE2b-256 6bfeab37f3808b9f90e85e63bd0f55837cb2dae54902d351132860af557bf1db

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.18.0 This release

2 files

0.17.4

2 files

0.17.0

2 files

0.15.3

2 files

0.15.1

2 files

0.14.2

2 files

0.14.1

2 files

0.12.6

2 files

0.12.5

2 files

0.12.4

2 files

0.12.3

2 files

0.12.2

2 files

0.11.4

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page