Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include README.md
include LICENSE

1 change: 1 addition & 0 deletions btchip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
* limitations under the License.
********************************************************************************
"""
__version__ = "0.1.32"

18 changes: 10 additions & 8 deletions btchip/btchip.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def __init__(self, dongle):
self.scriptBlockLength = 50
else:
self.scriptBlockLength = 255
except:
except Exception:
pass
try:
result = self.getJCExtendedFeatures()
self.needKeyCache = (result['proprietaryApi'] == False)
except:
except Exception:
pass

def setAlternateCoinVersion(self, versionRegular, versionP2SH):
Expand Down Expand Up @@ -230,10 +230,10 @@ def startUntrustedTransaction(self, newTransaction, inputIndex, outputList, rede
apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_START, 0x80, 0x00 ]
params = []
script = bytearray(redeemScript)
if ('witness' in passedOutput) and passedOutput['witness']:
params.append(0x02)
elif ('trustedInput' in passedOutput) and passedOutput['trustedInput']:
if ('trustedInput' in passedOutput) and passedOutput['trustedInput']:
params.append(0x01)
elif ('witness' in passedOutput) and passedOutput['witness']:
params.append(0x02)
else:
params.append(0x00)
if ('trustedInput' in passedOutput) and passedOutput['trustedInput']:
Expand All @@ -242,8 +242,6 @@ def startUntrustedTransaction(self, newTransaction, inputIndex, outputList, rede
if currentIndex != inputIndex:
script = bytearray()
writeVarint(len(script), params)
if len(script) == 0:
params.extend(sequence)
apdu.append(len(params))
apdu.extend(params)
self.dongle.exchange(bytearray(apdu))
Expand All @@ -261,6 +259,10 @@ def startUntrustedTransaction(self, newTransaction, inputIndex, outputList, rede
apdu.extend(params)
self.dongle.exchange(bytearray(apdu))
offset += blockLength
if len(script) == 0:
apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_START, 0x80, 0x00, len(sequence) ]
apdu.extend(sequence)
self.dongle.exchange(bytearray(apdu))
currentIndex += 1

def finalizeInput(self, outputAddress, amount, fees, changePath, rawTx=None):
Expand Down Expand Up @@ -296,7 +298,7 @@ def finalizeInput(self, outputAddress, amount, fees, changePath, rawTx=None):
response = self.dongle.exchange(bytearray(apdu))
offset += dataLength
alternateEncoding = True
except:
except Exception:
pass
if not alternateEncoding:
apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_FINALIZE, 0x02, 0x00 ]
Expand Down
10 changes: 5 additions & 5 deletions btchip/btchipComm.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def close(self):
if self.opened:
try:
self.device.close()
except:
except Exception:
pass
self.opened = False

Expand All @@ -169,7 +169,7 @@ def close(self):
if self.opened:
try:
self.device.disconnect()
except:
except Exception:
pass
self.opened = False

Expand All @@ -182,7 +182,7 @@ def __init__(self, server, port, debug=False):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((self.server, self.port))
except:
except Exception:
raise BTChipException("Proxy connection failed")

def exchange(self, apdu, timeout=20000):
Expand All @@ -202,7 +202,7 @@ def exchange(self, apdu, timeout=20000):
def close(self):
try:
self.socket.close()
except:
except Exception:
pass

def getDongle(debug=False):
Expand Down Expand Up @@ -244,7 +244,7 @@ def getDongle(debug=False):
else:
connection.disconnect()
connection = None
except:
except Exception:
connection = None
pass
if connection is not None:
Expand Down
2 changes: 1 addition & 1 deletion btchip/btchipKeyRecovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def recoverKey(signature, hashValue, keyX):
candidate = point_to_ser(key.pubkey.point)
if candidate[1:33] == keyX:
return candidate
except:
except Exception:
pass
raise Exception("Key recovery failed")
8 changes: 4 additions & 4 deletions btchip/btchipPersoWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
try:
from mnemonic import Mnemonic
MNEMONIC = True
except:
except Exception:
MNEMONIC = False

from .btchipComm import getDongle, DongleWait
Expand All @@ -51,7 +51,7 @@ def waitDongle(currentDialog, persoData):
if persoData['client'] != None:
try:
persoData['client'].dongle.close()
except:
except Exception:
pass
dongle = getDongle(BTCHIP_DEBUG)
persoData['client'] = btchip(dongle)
Expand Down Expand Up @@ -124,7 +124,7 @@ def processNext(self):
seedText = seedText[0:-1]
try:
self.persoData['seed'] = seedText.decode('hex')
except:
except Exception:
pass
if self.persoData['seed'] == None:
if not MNEMONIC:
Expand Down Expand Up @@ -279,7 +279,7 @@ def finish(self):
if not self.persoData['hardened']:
try:
self.persoData['client'].setOperationMode(btchip.OPERATION_MODE_SERVER)
except:
except Exception:
QMessageBox.warning(self, "Error", "Error switching to non hardened mode", "OK")
self.reject()
self.persoData['main'].reject()
Expand Down
2 changes: 1 addition & 1 deletion samples/runScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
if len(line) == 0:
continue
dongle.exchange(bytearray(binascii.unhexlify(line)), timeout)
except:
except Exception:
if cancelResponse:
pass
else:
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
from os.path import dirname, join

here = dirname(__file__)
import btchip
setup(
name='btchip-python',
version='0.1.28',
version=btchip.__version__,
author='BTChip',
author_email='hello@ledger.fr',
description='Python library to communicate with Ledger Nano dongle',
long_description=open(join(here, 'README.md')).read(),
url='https://github.com/LedgerHQ/btchip-python',
packages=find_packages(),
install_requires=['hidapi>=0.7.99'],
install_requires=['hidapi>=0.7.99', 'ecdsa>=0.9'],
extras_require = {
'smartcard': [ 'python-pyscard>=1.6.12-4build1', 'ecdsa>=0.9' ]
'smartcard': [ 'python-pyscard>=1.6.12-4build1' ]
},
include_package_data=True,
zip_safe=False,
Expand Down
2 changes: 1 addition & 1 deletion tests/testMessageSignature.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
app = btchip(dongle)
try:
app.setup(btchip.OPERATION_MODE_WALLET, btchip.FEATURE_RFC6979, 0x00, 0x05, "1234", None, btchip.QWERTY_KEYMAP, SEED)
except:
except Exception:
pass
# Authenticate
app.verifyPin("1234")
Expand Down
2 changes: 1 addition & 1 deletion tests/testMultisigArmory.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
app = btchip(dongle)
try:
app.setup(btchip.OPERATION_MODE_RELAXED_WALLET, btchip.FEATURE_RFC6979, 111, 196, "1234", None, btchip.QWERTY_KEYMAP, SEED)
except:
except Exception:
pass
# Authenticate
app.verifyPin("1234")
Expand Down
2 changes: 1 addition & 1 deletion tests/testMultisigArmoryNo2FA.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
app = btchip(dongle)
try:
app.setup(btchip.OPERATION_MODE_RELAXED_WALLET, btchip.FEATURE_RFC6979|btchip.FEATURE_NO_2FA_P2SH, 111, 196, "1234", None, btchip.QWERTY_KEYMAP, SEED)
except:
except Exception:
pass
# Authenticate
app.verifyPin("1234")
Expand Down
2 changes: 1 addition & 1 deletion tests/testSimpleTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
app = btchip(dongle)
try:
app.setup(btchip.OPERATION_MODE_WALLET, btchip.FEATURE_RFC6979, 0x00, 0x05, "1234", None, btchip.QWERTY_KEYMAP, SEED)
except:
except Exception:
pass
# Authenticate
app.verifyPin("1234")
Expand Down