Skip to main content

Communicate with your Coldcard using Python

Project description

Coldcard CLI and Python Interface Library

Coldcard is a Cheap, Ultra-secure & Opensource Hardware Wallet for #Bitcoin.

Get yours at ColdcardWallet.com

This is the python code and command-line utilities you need to communicate with it over USB.

Setup For Everyday Use

  • pip install 'ckcc-protocol[cli]'

This installs a single helpful command line program: ckcc

If you just want the python library, use:

  • pip install ckcc-protocol

Setup If You Might Change the Code

  • do a git checkout
  • probably make a fresh virtual env
  • run:
pip install -r requirements.txt
pip install --editable '.[cli]'

Requirements

  • python 3.6 or higher
  • hidapi for USB HID access in a portable way.
  • see requirements.txt file for more details.

CLI Examples

Command Arguments

% ckcc
Usage: ckcc [OPTIONS] COMMAND [ARGS]...

Options:
  -s, --serial HEX  Operate on specific unit (default: first found)
  -x, --simulator   Connect to the simulator via Unix socket
  -P, --plaintext   Disable USB link-layer encryption
  --help            Show this message and exit.

Commands:
  addr        Show the human version of an address
  auth        Indicate specific user is present (for HSM).
  backup      Creates 7z encrypted backup file after prompting user to...
  bag         Factory: set or read bag number -- single use only!
  chain       Get which blockchain (Bitcoin/Testnet) is configured.
  debug       Start interactive (local) debug session
  eval        Simulator only: eval a python statement
  exec        Simulator only: exec a python script
  get-locker  Get the value held in the Storage Locker (not Bitcoin...
  hsm         Get current status of HSM feature.
  hsm-start   Enable Hardware Security Module (HSM) mode.
  list        List all attached Coldcard devices
  local-conf  Generate the 6-digit code needed for a specific PSBT file...
  logout      Securely logout of device (will require replug to start over)
  msg         Sign a short text message
  multisig    Create a skeleton file which defines a multisig wallet.
  p2sh        Show a multisig payment address on-screen.
  pass        Provide a BIP39 passphrase
  pubkey      Get the public key for a derivation path
  reboot      Reboot coldcard, force relogin and start over
  sign        Approve a spending transaction by signing it on Coldcard
  test        Test USB connection (debug/dev)
  upgrade     Send firmware file (.dfu) and trigger upgrade process
  upload      Send file to Coldcard (PSBT transaction or firmware)
  user        Create a new user on the Coldcard for HSM policy (also...
  version     Get the version of the firmware installed
  xfp         Get the fingerprint for this wallet (master level)
  xpub        Get the XPUB for this wallet (master level, or any derivation)

Message Signing

% ckcc msg --help
Usage: ckcc msg [OPTIONS] MESSAGE

  Sign a short text message

Options:
  -p, --path DERIVATION  Derivation for key to use [default: m/44'/0'/0'/0/0]
  -v, --verbose          Include fancy ascii armour
  -j, --just-sig         Just the signature itself, nothing more
  -s, --segwit           Address in segwit native (p2wpkh, bech32)
  -w, --wrap             Address in segwit wrapped in P2SH (p2wpkh)
  --help                 Show this message and exit.

% ckcc msg "Hello Coldcard" -p m/34/23/33
Waiting for OK on the Coldcard...
Hello Coldcard                    
1KSXaNHh3G4sfTMsp9q8CmACeqsJn46drd
H4mTuwMUdnu3MyMA+6aJ3hiAF4L0WBDZFseTEno511hNN8/THIeM4GW4SnrcJJhS3WxMZEWFdEIZDSP+H5aIcao=

Transaction Signing

% ckcc sign --help
Usage: ckcc sign [OPTIONS] PSBT_IN [PSBT_OUT]

  Approve a spending transaction by signing it on Coldcard

Options:
  -v, --verbose    Show more details
  -f, --finalize   Show final signed transaction, ready for transmission
  -z, --visualize  Show text of Coldcard's interpretation of the transaction
                   (does not create transaction, no interaction needed)
  -s, --signed     Include a signature over visualization text
  -x, --hex        Write out (signed) PSBT in hexidecimal
  -6, --base64     Write out (signed) PSBT encoded in base64
  --help           Show this message and exit.

% (... acquire PSBT file for what you want to do ...)

% ckcc sign example.psbt out.psbt
5071 bytes (start @ 0) to send from 'example.psbt'
Uploading  [####################################]  100%
Waiting for OK on the Coldcard...
Ok! Downloading result (5119 bytes)

%  hexdump -C out.psbt | head -3
00000000  70 73 62 74 ff 01 00 fd  22 04 02 00 00 00 04 3f  |psbt...."......?|
00000010  ee 16 30 9d 14 82 36 dd  c8 3e 9e 4f 94 47 83 00  |..0...6..>.O.G..|
00000020  c2 23 e1 06 22 1b 02 0e  bd c8 1c 71 79 7d 3c 02  |.#.."......qy}<.|
00000030  00 00 00 00 fe ff ff ff  4c 85 a0 2c 80 cb 2c 01  |........L..,..,.|

Project details


Download files

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

Source Distribution

ckcc-protocol-1.2.1.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

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

ckcc_protocol-1.2.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file ckcc-protocol-1.2.1.tar.gz.

File metadata

  • Download URL: ckcc-protocol-1.2.1.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.16

File hashes

Hashes for ckcc-protocol-1.2.1.tar.gz
Algorithm Hash digest
SHA256 65f0313f9915b36068f6dfcab08e04671621e6227650443bc12e81997081ae7f
MD5 585320e1566e67b24a2e57ce344ace5e
BLAKE2b-256 3a3b7561991acddfc07b4b60296f9b9539b3fca1f53df8b99d2fa1f54ab1bd98

See more details on using hashes here.

File details

Details for the file ckcc_protocol-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: ckcc_protocol-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.16

File hashes

Hashes for ckcc_protocol-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae1f4303ffd453e826501fd8942256639b2d67bf30c5a3aae4a0ed3ec4501a78
MD5 d84a2fca4cdf5e66d73e650c021e6a34
BLAKE2b-256 8f6b95d8ceef776fa2940af3eaac6a34f70a62b3a030f0d2bcbf3acf7c5ec665

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page