Giter Site home page Giter Site logo

btchip-python's Introduction

btchip-python

Python communication library for Ledger Hardware Wallet products

Requirements

This API is available on pip - install with pip install btchip-python

Building on a Unix platform requires libusb-1.0-0-dev and libudev-dev installed previously

Interim Debian packages have also been built by Richard Ulrich at https://launchpad.net/~richi-paraeasy/+archive/ubuntu/bitcoin/ (btchip-python, hidapi and python-hidapi)

For optional BIP 39 support during dongle setup, also install https://github.com/trezor/python-mnemonic - also available as a Debian package at the previous link (python-mnemonic)

Building on Windows

Building/Installing on FreeBSD

On FreeBSD you can install the packages:

pkg install security/py-btchip-python

or build via ports:

cd /usr/ports/security/py-btchip-python
make install clean

btchip-python's People

Contributors

achow101 avatar brandoncurtis avatar drizzt avatar ehaupt avatar fametrano avatar instagibbs avatar skorokithakis avatar tamtamhero avatar ulrichard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

btchip-python's Issues

Share account between trezor and hw1

Is it possible to share a trezor account with hw1?
If I have the trezor seed, could I calculate the MPK for one of its accounts, and then transform it to the format used by HW1 for the seed?
I know pycoin has some key derivation functions exposed, but I don't know how much format conversion is needed at different steps.

system freeze

During testing today my notebook froze several times, so that I had to hard reset it.
I cant remember what I did every time. At least two times were, when I removed the HW1 while electrum didn't respond for some minutes.
The last occurrence was when trying to sign a message after resetting the dongle. Then a dialog popped up asking if I wanted to initialize it. When I clicked cancel, the whole system froze.
I 've had that notebook for about a year. Before today, I froze maybe twice.

value must be between 0 and 255

From time to time, I get the message "value must be between 0 and 255" when trying to send BitCoins in electrum. I'm not entirely sure about the source of the problem. But I can always solve it by reducing the input set. That means I go to the address tab, select one or more addresses, and click "send from".

Unable to send raw transaction: Signature must be zero for failed CHECK(MULTI)SIG operation

When I send a raw transaction I get an error:
16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)

Raw transaction that I send:
0200000001d18e181dc31f713573785c4434b70c415b407e200959f10d24a5eee72a4bae3401000000da00473044022038b7aaf811db578a0b62b1ff69f7b2a6054cd9b770275b292ff63bb6b6faa96902202ffa91a950c8976722284a0bcd3ad9c54e11e441f9f632c3dd76f9174f1d0c0a01483045022100a3c48312f94652269b6e23b3e48ead21b788a2d162205d9ba4c01c9cddfc9ea70220772828f03307eaf90cc17f12f2f97e8424ff5f5311839b4095f775813cb2dada014752210283910b39cc9fab5ca7ad622dbe4a09e13ce53232b8695f96315c6e90c64c526e2103e88f91c7e130cc2f760d82b8135af8ec493860b0943649c65e0daf8b3b5a945552aeffffffff01962af4050000000017a9146fb7855fc9f0fcad63dacb27103f3ee6089b65408700000000

This raw transaction decoded:

{
  "txid": "e63230d2b56bec46ab1273f0962f0fce43248fb1acbd7214be5a319b53fc170e",
  "hash": "e63230d2b56bec46ab1273f0962f0fce43248fb1acbd7214be5a319b53fc170e",
  "version": 2,
  "size": 301,
  "vsize": 301,
  "locktime": 0,
  "vin": [
    {
      "txid": "34ae4b2ae7eea5240df15909207e405b410cb734445c787335711fc31d188ed1",
      "vout": 1,
      "scriptSig": {
        "asm": "0 3044022038b7aaf811db578a0b62b1ff69f7b2a6054cd9b770275b292ff63bb6b6faa96902202ffa91a950c8976722284a0bcd3ad9c54e11e441f9f632c3dd76f9174f1d0c0a[ALL] 3045022100a3c48312f94652269b6e23b3e48ead21b788a2d162205d9ba4c01c9cddfc9ea70220772828f03307eaf90cc17f12f2f97e8424ff5f5311839b4095f775813cb2dada[ALL] 52210283910b39cc9fab5ca7ad622dbe4a09e13ce53232b8695f96315c6e90c64c526e2103e88f91c7e130cc2f760d82b8135af8ec493860b0943649c65e0daf8b3b5a945552ae",
        "hex": "00473044022038b7aaf811db578a0b62b1ff69f7b2a6054cd9b770275b292ff63bb6b6faa96902202ffa91a950c8976722284a0bcd3ad9c54e11e441f9f632c3dd76f9174f1d0c0a01483045022100a3c48312f94652269b6e23b3e48ead21b788a2d162205d9ba4c01c9cddfc9ea70220772828f03307eaf90cc17f12f2f97e8424ff5f5311839b4095f775813cb2dada014752210283910b39cc9fab5ca7ad622dbe4a09e13ce53232b8695f96315c6e90c64c526e2103e88f91c7e130cc2f760d82b8135af8ec493860b0943649c65e0daf8b3b5a945552ae"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.99887766,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 6fb7855fc9f0fcad63dacb27103f3ee6089b6540 OP_EQUAL",
        "hex": "a9146fb7855fc9f0fcad63dacb27103f3ee6089b654087",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N3RvqqdX1ou9brMRThsr9hdJpHXPkDGXt9"
        ]
      }
    }
  ]
}

UTX that raw transaction tries to spend:
34ae4b2ae7eea5240df15909207e405b410cb734445c787335711fc31d188ed1

UTX pubKey script section:
a9146fb7855fc9f0fcad63dacb27103f3ee6089b654087

ScriptSig:
00473044022038b7aaf811db578a0b62b1ff69f7b2a6054cd9b770275b292ff63bb6b6faa96902202ffa91a950c8976722284a0bcd3ad9c54e11e441f9f632c3dd76f9174f1d0c0a01483045022100a3c48312f94652269b6e23b3e48ead21b788a2d162205d9ba4c01c9cddfc9ea70220772828f03307eaf90cc17f12f2f97e8424ff5f5311839b4095f775813cb2dada014752210283910b39cc9fab5ca7ad622dbe4a09e13ce53232b8695f96315c6e90c64c526e2103e88f91c7e130cc2f760d82b8135af8ec493860b0943649c65e0daf8b3b5a945552ae

When I debug a script with online debugger it executes well: http://paulkernfeld.com/bse/
Online debugger is unhappy about last opcode 0x87 OP_EQUAL, but it may be the debugger limitation only:
a9146fb7855fc9f0fcad63dacb27103f3ee6089b654087

What is wrong with my raw transaction that I try to broadcast?
Why does OP_CHECKMULTISIG fail?

I think that OP_CHECKMULTISIG comes from redeemScript:

52210283910b39cc9fab5ca7ad622dbe4a09e13ce53232b8695f96315c6e90c64c526e2103e88f91c7e130cc2f760d82b8135af8ec493860b0943649c65e0daf8b3b5a945552ae

The redeemScript decoded:
2 0283910b39cc9fab5ca7ad622dbe4a09e13ce53232b8695f96315c6e90c64c526e 03e88f91c7e130cc2f760d82b8135af8ec493860b0943649c65e0daf8b3b5a9455 2 OP_CHECKMULTISIG

I played with signatures order but it didn't help.

Invalid Channel

Having issues trying to connect my Ledger Nano S (Firmware 1.31) to Electron-Cash 3.1.2 OSX running the Bitcoin Cash Ledger app (v1.1.5).

The application correctly detects my Ledger device however attempting to establish a connection results in the error: "Exception: Invalid Channel"

I have been working with the developer of the application to isolate the issue and it appears to be a btchip-python error message:
https://github.com/LedgerHQ/btchip-python/blob/master/btchip/ledgerWrapper.py#L55
https://github.com/LedgerHQ/btchip-python/blob/master/btchip/ledgerWrapper.py#L78

Could this be a problem with the Ledger Bitcoin Cash App? If I launch the Bitcoin App instead I receive a different error - "HW1 firmware version too old. Please update at ledgerwallet.com" and the Bitcoin app works fine with electrum (https://github.com/spesmilo/electrum) whose code was forked for the BCH variant.

Please help!

Cheers

Can't build btchip-python wheel anymore

When I try to install btchip-python via pip install btchip-python I get this due to something being wrong with the setup.py file which prevents it from installing:

      running install_scripts
      Traceback (most recent call last):
        File "/usr/lib/python3.11/site-packages/packaging/requirements.py", line 35, in __init__
          parsed = _parse_requirement(requirement_string)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/site-packages/packaging/_parser.py", line 64, in parse_requirement
          return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/site-packages/packaging/_parser.py", line 82, in _parse_requirement
          url, specifier, marker = _parse_requirement_details(tokenizer)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/site-packages/packaging/_parser.py", line 126, in _parse_requirement_details
          marker = _parse_requirement_marker(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/site-packages/packaging/_parser.py", line 147, in _parse_requirement_marker
          tokenizer.raise_syntax_error(
        File "/usr/lib/python3.11/site-packages/packaging/_tokenizer.py", line 165, in raise_syntax_error
          raise ParserSyntaxError(
      packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after version specifier)
          python-pyscard>=1.6.12-4build1
                        ~~~~~~~~~~^

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-ejw6ui8h/btchip-python_cd0a9c8abd924937b5736601c67fb5c6/setup.py", line 9, in <module>
          setup(
        File "/home/lemon/.local/lib/python3.11/site-packages/setuptools/__init__.py", line 153, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/lemon/.local/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/home/lemon/.local/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
          self.run_command(cmd)
        File "/home/lemon/.local/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
          cmd_obj.run()
        File "/usr/lib/python3.11/site-packages/wheel/bdist_wheel.py", line 395, in run
          self.egg2dist(self.egginfo_dir, distinfo_dir)
        File "/usr/lib/python3.11/site-packages/wheel/bdist_wheel.py", line 534, in egg2dist
          pkg_info = pkginfo_to_metadata(egginfo_path, pkginfo_path)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/site-packages/wheel/metadata.py", line 160, in pkginfo_to_metadata
          for key, value in generate_requirements({extra: reqs}):
        File "/usr/lib/python3.11/site-packages/wheel/metadata.py", line 138, in generate_requirements
          for new_req in convert_requirements(depends):
        File "/usr/lib/python3.11/site-packages/wheel/metadata.py", line 103, in convert_requirements
          parsed_requirement = Requirement(req)
                               ^^^^^^^^^^^^^^^^
        File "/usr/lib/python3.11/site-packages/packaging/requirements.py", line 37, in __init__
          raise InvalidRequirement(str(e)) from e
      packaging.requirements.InvalidRequirement: Expected end or semicolon (after version specifier)
          python-pyscard>=1.6.12-4build1
                        ~~~~~~~~~~^
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for btchip-python
  Running setup.py clean for btchip-python
Failed to build btchip-python
ERROR: Could not build wheels for btchip-python, which is required to install pyproject.toml-based projects

restore wallet

Trying to restore a hw1 wallet from a seed in electrum never succeeded for me so far.
When I click new/restore then restore with hardware wallet, then BTChip, nothing happens.
Is this implemented at all?
Creating a new wallet with BTChip works and gives me a seed for backup.
But I want to initialize a second HW1 with the same seed.

Once that works, would the two be fully interchangeable, or do I have to have two separate electrum wallet files, that essentially manage the same private keys, but with a different hardware ID?

Btchip (electrum) not able to sign bulk transactions

I've set my btchip in relaxed wallet mode, and now i should be able to sign transactions with how many outputs i want. But when i try to load a CSV range of address + amounts with the dedicated feature in electrum, the button "Sign" just does not appear.

schermata del 2015-05-08 09 58 29

Can't open Ledger with the latest Bitcoin app selected

Bitcoin app version: 1.5.1
OS: Ubuntu 20
hid detects Ledger, but open of the device fails.
This breaks communication with Ledger for HWI and Specter.

>>> from btchip import btchipComm
>>> btchipComm.getDongle()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ss/dev/desktop/myspecter/.venv/lib/python3.8/site-packages/btchip/btchipComm.py", line 230, in getDongle
    dev.open_path(hidDevicePath)
  File "hid.pyx", line 72, in hid.device.open_path
OSError: open failed

FIXED: Problems installing btchip-pyhon on Ubuntu 17.x via PIP

My first attempt pip install btchip-python failed and error message suggested I lack libusb package. I fixed this by doing pip install libusb, yet btchip-python installation was still failing, this time with:

....
hidapi/libusb/hid.c:47:20: fatal error: libusb.h: No such file or directory

I installed missling dev package:

apt install libusb-dev

but it did not help much, and it was still failing the same way. It appears that on Ubuntu/Debian you need to install libusb-1.0.0-dev instead of libusb-dev:

apt install libusb-1.0.0-dev

This solved my problem, but instead it started failing

....
/usr/bin/ld: cannot find -ludev

which I solved with

apt install libudev-dev

This time all worked fine

$ pip install btchip-python
Collecting btchip-python
Collecting hidapi>=0.7.99 (from btchip-python)
  Using cached hidapi-0.7.99.post21.tar.gz
Collecting setuptools>=19.0 (from hidapi>=0.7.99->btchip-python)
  Using cached setuptools-36.6.0-py2.py3-none-any.whl
Building wheels for collected packages: hidapi
  Running setup.py bdist_wheel for hidapi ... done
  Stored in directory: /<PATH>/.cache/pip/wheels/90/ea/5c/9827ea51c117f43a0df937f29d02630ecf0bdbc3e5b2fa2bba
Successfully built hidapi
Installing collected packages: setuptools, hidapi, btchip-python
Successfully installed btchip-python-0.1.21 hidapi-0.7.99.post21 setuptools-36.6.0

If you do not have to install it via PIP, then

apt install python-btchip

would be much less painful.

Hope this helps.

"pip install btchip-python" does not work, runs into error

Here is what I get when trying to install it:

pip install btchip-python
Collecting btchip-python
Collecting hidapi>=0.7.99 (from btchip-python)
Using cached hidapi-0.7.99.post20.tar.gz
Collecting setuptools>=19.0 (from hidapi>=0.7.99->btchip-python)
Using cached setuptools-36.2.7-py2.py3-none-any.whl
Building wheels for collected packages: hidapi
Running setup.py bdist_wheel for hidapi ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-mXtvEp/hidapi/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" bdist_wheel -d /tmp/tmp7zOcANpip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_ext
cythoning hid.pyx to hid.c
building 'hid' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/hidapi
creating build/temp.linux-x86_64-2.7/hidapi/libusb
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python2.7 -c hid.c -o build/temp.linux-x86_64-2.7/hid.o
hid.c: In function ‘__pyx_pf_3hid_6device_open’:
hid.c:1720:45: warning: passing argument 1 of ‘PyUnicodeUCS4_AsWideChar’ from incompatible pointer type [-Wincompatible-pointer-types]
__pyx_v_result = PyUnicode_AsWideChar(__pyx_v_serial_number, __pyx_v_cserial_number, __pyx_v_serial_len);
^
In file included from /usr/include/python2.7/Python.h:85:0,
from hid.c:4:
/usr/include/python2.7/unicodeobject.h:246:31: note: expected ‘PyUnicodeObject * {aka struct *}’ but argument is of type ‘PyObject * {aka struct _object *}’
define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar
^
/usr/include/python2.7/unicodeobject.h:591:24: note: in expansion of macro ‘PyUnicode_AsWideChar’
PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
^
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python2.7 -c hidapi/libusb/hid.c -o build/temp.linux-x86_64-2.7/hidapi/libusb/hid.o
hidapi/libusb/hid.c:47:20: fatal error: libusb.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I tried to install with sudo apt-get install python-btchip but this only installs an older version which misses the attribute enableAlternate2fa which is needed by the referencing software!

freezing electrum

When I want to sign transactions it often happens that electrum freezes, when it waits for an operation from hw1. It's no always at the same time. Sometimes it is before entering the PIN, sometimes after the PIN and sometimes after entering the TAN that it typed on the other device. Normally, none of these operations take more than a few seconds.
If electrum freezes for two minutes, I pull the hw1 from the USB port, and electrum becomes responsive immediately, showing some error message. It's not always the same message, but one that I can remember is that it couldn't find the device.
On average I need to start over two or three times before the transaction is successfully signed. It's usually no big deal, but today I needed six attempts. That triggered me to finally report the issue.

WinUSBDongle constructor interface mismatch

After updating to the most recent version, my HW1 with WinUSB does no longer work.
At first sight it might be because the interface doesn't match :

class WinUSBDongle(Dongle, DongleWait):
def init(self, device, debug=False):

...

return WinUSBDongle(dev, ledger, debug)

I can get it to work by simply removing the ledger variable from the instantiation. Although I have no idea if that's the right fix.

Invalid status 6702 in getFirmwareVersion after latest firmware upgrade

Hi, I upgraded the firmware for my Nano X from 2.0.0 to 2.0.2, and now I'm getting this error:


    firmwareInfo = self.dongleObject.getFirmwareVersion()
  File "/home/pierre/.local/lib/python3.10/site-packages/btchip/btchip.py", line 563, in getFirmwareVersion
    response = self.dongle.exchange(bytearray(apdu))
  File "/home/pierre/.local/lib/python3.10/site-packages/btchip/btchipComm.py", line 127, in exchange
    raise BTChipException("Invalid status %04x" % sw, sw)
btchip.btchipException.BTChipException: Exception : Invalid status 6702

mnemonic wordlist missing

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/btchip_python-0.1.1-py2.7.egg/btchip/btchipPersoWizard.py", line 86, in processNext
dialog = SeedDialog(persoData, self)
File "/usr/local/lib/python2.7/dist-packages/btchip_python-0.1.1-py2.7.egg/btchip/btchipPersoWizard.py", line 106, in init
self.mnemonic = Mnemonic('english')
File "/usr/local/lib/python2.7/dist-packages/mnemonic/mnemonic.py", line 34, in init
self.wordlist = [w.strip() for w in open('%s/%s.txt' % (self._get_directory(), language), 'r').readlines()]
IOError: [Errno 2] Datei oder Verzeichnis nicht gefunden: '/usr/local/lib/python2.7/dist-packages/mnemonic/wordlist/english.txt'

$ ls -l /usr/local/lib/python2.7/dist-packages/mnemonic/
insgesamt 20
-rw-r--r-- 1 root staff 30 Jul 30 20:30 init.py
-rw-r--r-- 1 root staff 203 Jul 30 20:30 init.pyc
-rw-r--r-- 1 root staff 3741 Jul 30 20:30 mnemonic.py
-rw-r--r-- 1 root staff 4802 Jul 30 20:30 mnemonic.pyc

wordlist directory is entirely missing.

"enableAlternate2fa" error when using standard install on Ubuntu 16.04

Objective: using Ledger Nano S with Electrum to sign a bitcoin transaction

Electrum 2.9.3
Ledger bitcoin app: 1.1.10
Ubuntu 16.04
official ubuntu repo: btchip-python 0.1.16-1

This error happens:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/electrum_plugins/ledger/ledger.py", line 365, in sign_transaction
    self.get_client().enableAlternate2fa(False)
AttributeError: btchip instance has no attribute 'enableAlternate2fa'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/electrum_gui/qt/util.py", line 582, in run
    result = task.task()
  File "/usr/local/lib/python2.7/dist-packages/electrum/wallet.py", line 1141, in sign_transaction
    k.sign_transaction(tx, password)
  File "/usr/local/lib/python2.7/dist-packages/electrum_plugins/ledger/ledger.py", line 422, in sign_transaction
    self.give_error(e, True)
  File "/usr/local/lib/python2.7/dist-packages/electrum_plugins/ledger/ledger.py", line 201, in give_error
    raise Exception(message)
Exception: btchip instance has no attribute 'enableAlternate2fa'

the workaround was to install with PIP version 0.1.24

Exception: Invalid status 6700 when using getFirmwareVersion()

On Ubuntu 17.10 using Python 3.6. Ledger Nano S is connected and unlocked.

After installing btchip-python with pip3 I ran the following code from getFirmwareVersion.py:

from btchip.btchip import *
import sys
dongle = getDongle(True)
app = btchip(dongle)
print(app.getFirmwareVersion()['version'])

The 4th line prints the following output:

=> b'e0c4000000'
<= b''6700
=> b'f026000000'
<= b''6e00

When executing the getFirmwareVersion() function in the 5th line I get output:

=> b'e0c4000000'
<= b''6700

And error:

BTChipException Traceback (most recent call last)
<ipython-input-4-9d5272afbb74> in <module>()
----> 1 app.getFirmwareVersion()

/home/username/.local/lib/python3.6/site-packages/btchip/btchip.py in getFirmwareVersion(self)
559 apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_GET_FIRMWARE_VERSION, 0x00, 0x00, 0x00 ]
560 try:
--> 561 response = self.dongle.exchange(bytearray(apdu))
562 except BTChipException as e:
563 if (e.sw == 0x6985):

/home/username/.local/lib/python3.6/site-packages/btchip/btchipComm.py in exchange(self, apdu, timeout)
125 print("<= %s%.2x" % (hexlify(response), sw))
126 if sw != 0x9000:
--> 127 raise BTChipException("Invalid status %04x" % sw, sw)
128 return response
129

BTChipException: Exception : Invalid status 6700

pip installation

please make btchip available throug pip, or even better an apt-get ppa.

Missing release v0.1.32

Please tag release v0.1.32. Currently the packages in Arch Linux use the last tagged release 0.1.31 and the latest version of Electrum (4.1.0) cannot be used with Ledger on Arch Linux because it requires 0.1.32

Support for newer firmware releases

I have to HW1 that work with btchip-python, and two that don't.
The test I use is samples/getFirmwareVersion.py
The ones that work have firmware version 1.4.10 and 1.4.14
The ones that don't work are:

  1. upgraded to the latest firmware with the chromium plugin a few days ago.
  2. received per mail today and set up with Ledger Starter.

So it appears to me, the python lib doesn't support newer firmwares.

typing the next available receiving address

It would be cool, if there was a mode, where the hw1 would type out the next available receiving address. Say I go to somebody for buying some BitCoin. I could then just plug my hw1 into his computer, and it would type the address where he can send the coins.
But that's where my idea ends. I don't really know how that would best be triggered. For instance, if the hw1 is connected to a computer, and no software connects to it for say 30 seconds. Could it then switch to HID mode, and start typing. I'm not really sure if that's a good idea, as it could also disturb normal operation.
Of course, the device can't figure out this information on it's own. So, the client program would have to write the info to the device when it sycs with the blockchain.

__version__ attribute

Implement the module __version__ attribute from PEP 396.

Example behavior:

>>> import btchip
>>> btchip.__version__
'0.1.27'

This is useful for developers to better handle different versions of python-btchip, and their respective feature-sets.

argument count of the read function

I'm in the process of packaging btchip-python for debian.
For as long as pyusb is in beta, I created an intermediary package for pyusb v1 from https://github.com/walac/pyusb.
Now I get errors
TypeError: read() takes at most 4 arguments (5 given)
about mismatching argument count between
https://github.com/btchip/btchip-python/blob/master/btchip/btchipComm.py line 134
https://github.com/walac/pyusb/blob/master/usb/core.py line 351

On the other computer, where I installed pyusb with "sudo python setup.py install" from the git working copy, I don't get the problem.

Somebody with more insight is probably quicker than me to find out what's wrong.

signing multisig transactions

Is is possible with this API to sign multisign transactions?
I created a multisig address with addresses from trezor and hw1.
Funding was no problem, but redeeming turns out to be more problematic than I anticipated.
I learned that trezor doesn't support that yet.
Since hw1 must do something like that with GreenAddress, I might be more lucky here.
After a quick look at testSimpleTransaction.py , they all require a key derivation path.
Are there other functions, or would I have to pass special parameters?

Add sapling support to btchip-python

At the very least, I think p2 here needs to be 0x05 for sapling transactions (And in the subsequent uses);

apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_START, 0x00, p2 ]

But I'd rather check with someone more familiar with this code on the best approach before PR.

I tried it out and it seems to crash the device and disconnect the USB, but that could be to do with the subsequent calls. I'm working on setting up debugging

hw.1 support

I'm trying to get my old hw.1 to work in electrum. samples/getFirmwareVersion.py doesn't see the device (matching udev rule is in place).

I see in btchipComm.py the usb id of the hw.1 (2581:1b7c) isn't recognized?

Was hw.1 support dropped? I remember using it sucessfully years ago with electrum.

Invalid Status 6a80 when signing

Hi,
an electron-cash user has problems signing using his Ledger Blue (same with his ledger nano s).

Traceback (most recent call last):
File "/home/steffen/Desktop/Electron Cash-2.9.3/plugins/ledger/ledger.py", line 411, in sign_transaction
inputSignature = self.get_client().untrustedHashSign(inputsPaths[inputIndex], pin, lockTime=tx.locktime)
File "/usr/lib/python2.7/dist-packages/btchip/btchip.py", line 387, in untrustedHashSign
result = self.dongle.exchange(bytearray(apdu))
File "/usr/lib/python2.7/dist-packages/btchip/btchipComm.py", line 119, in exchange
raise BTChipException("Invalid status %04x" % sw, sw)
BTChipException: Exception : Invalid status 6a80
Exception : Invalid status 6a80
Traceback (most recent call last):
File "/home/steffen/Desktop/Electron Cash-2.9.3/gui/qt/util.py", line 582, in run
result = task.task()
File "/home/steffen/Desktop/Electron Cash-2.9.3/lib/wallet.py", line 1104, in sign_transaction
k.sign_transaction(tx, password)
File "/home/steffen/Desktop/Electron Cash-2.9.3/plugins/ledger/ledger.py", line 422, in sign_transaction
self.give_error(e, True)
File "/home/steffen/Desktop/Electron Cash-2.9.3/plugins/ledger/ledger.py", line 201, in give_error
raise Exception(message)
Exception: Exception : Invalid status 6a80

in reference to electron-cash issue Electron-Cash/Electron-Cash#153, especially this comment by the user: Electron-Cash/Electron-Cash#153 (comment)

This might not be a btchip issue, but I'm not familiar enough with this signing process to be able to figure out what's going on here.

Any help appreciated.

pip install pyusb failed on ubuntu 14.04

$ sudo pip install --upgrade pyusb
Downloading/unpacking pyusb
Could not find a version that satisfies the requirement pyusb (from versions: 1.0.0a2, 1.0.0a2, 1.0.0a3, 1.0.0a3, 1.0.0b1)
Cleaning up...
No distributions matching the version for pyusb
Storing debug log for failure in /home/richi/.pip/pip.log

apt-get installing it leads to the same problem as mentioned in the linked blog post, as it installs an older version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.