Merge pull request #3703 from SomberNight/ledger_pin_lock_exc

ledger: handle pin-locked state better
This commit is contained in:
ThomasV 2018-01-12 08:03:41 +01:00 committed by GitHub
commit 333b17fa60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,6 +60,21 @@ class Ledger_Client():
def versiontuple(self, v): def versiontuple(self, v):
return tuple(map(int, (v.split(".")))) return tuple(map(int, (v.split("."))))
def test_pin_unlocked(func):
"""Function decorator to test the Ledger for being unlocked, and if not,
raise a human-readable exception.
"""
def catch_exception(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except BTChipException as e:
if e.sw == 0x6982:
raise Exception(_('Your Ledger is locked. Please unlock it.'))
else:
raise
return catch_exception
@test_pin_unlocked
def get_xpub(self, bip32_path, xtype): def get_xpub(self, bip32_path, xtype):
self.checkDevice() self.checkDevice()
# bip32_path is of the form 44'/0'/1' # bip32_path is of the form 44'/0'/1'
@ -80,7 +95,7 @@ class Ledger_Client():
if len(splitPath) > 1: if len(splitPath) > 1:
prevPath = "/".join(splitPath[0:len(splitPath) - 1]) prevPath = "/".join(splitPath[0:len(splitPath) - 1])
nodeData = self.dongleObject.getWalletPublicKey(prevPath) nodeData = self.dongleObject.getWalletPublicKey(prevPath)
publicKey = compress_public_key(nodeData['publicKey'])# publicKey = compress_public_key(nodeData['publicKey'])
h = hashlib.new('ripemd160') h = hashlib.new('ripemd160')
h.update(hashlib.sha256(publicKey).digest()) h.update(hashlib.sha256(publicKey).digest())
fingerprint = unpack(">I", h.digest()[0:4])[0] fingerprint = unpack(">I", h.digest()[0:4])[0]