"""Function decorator to test the Ledger for being unlocked, and if not,
raiseahuman-readableexception.
"""
defcatch_exception(self,*args,**kwargs):
try:
returnfunc(self,*args,**kwargs)
exceptBTChipExceptionase:
ife.sw==0x6982:
raiseException(_('Your Ledger is locked. Please unlock it.'))
else:
raise
returncatch_exception
classLedger_Client():
classLedger_Client():
def__init__(self,hidDevice):
def__init__(self,hidDevice):
self.dongleObject=btchip(hidDevice)
self.dongleObject=btchip(hidDevice)
@ -64,20 +79,6 @@ class Ledger_Client():
returnFalse
returnFalse
returnTrue
returnTrue
deftest_pin_unlocked(func):
"""Function decorator to test the Ledger for being unlocked, and if not,
raiseahuman-readableexception.
"""
defcatch_exception(self,*args,**kwargs):
try:
returnfunc(self,*args,**kwargs)
exceptBTChipExceptionase:
ife.sw==0x6982:
raiseException(_('Your Ledger is locked. Please unlock it.'))
else:
raise
returncatch_exception
@test_pin_unlocked
@test_pin_unlocked
defget_xpub(self,bip32_path,xtype):
defget_xpub(self,bip32_path,xtype):
self.checkDevice()
self.checkDevice()
@ -256,6 +257,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
defdecrypt_message(self,pubkey,message,password):
defdecrypt_message(self,pubkey,message,password):
raiseRuntimeError(_('Encryption and decryption are currently not supported for {}').format(self.device))
raiseRuntimeError(_('Encryption and decryption are currently not supported for {}').format(self.device))
@test_pin_unlocked
@set_and_unset_signing
@set_and_unset_signing
defsign_message(self,sequence,message,password):
defsign_message(self,sequence,message,password):
message=message.encode('utf8')
message=message.encode('utf8')
@ -278,6 +280,8 @@ class Ledger_KeyStore(Hardware_KeyStore):
self.give_error("Unfortunately, this message cannot be signed by the Ledger wallet. Only alphanumerical messages shorter than 140 characters are supported. Please remove any extra characters (tab, carriage return) and retry.")
self.give_error("Unfortunately, this message cannot be signed by the Ledger wallet. Only alphanumerical messages shorter than 140 characters are supported. Please remove any extra characters (tab, carriage return) and retry.")
elife.sw==0x6985:# cancelled by user
elife.sw==0x6985:# cancelled by user
returnb''
returnb''
elife.sw==0x6982:
raise# pin lock. decorator will catch it
else:
else:
self.give_error(e,True)
self.give_error(e,True)
exceptUserWarning:
exceptUserWarning:
@ -299,6 +303,7 @@ class Ledger_KeyStore(Hardware_KeyStore):
# And convert it
# And convert it
returnbytes([27+4+(signature[0]&0x01)])+r+s
returnbytes([27+4+(signature[0]&0x01)])+r+s
@test_pin_unlocked
@set_and_unset_signing
@set_and_unset_signing
defsign_transaction(self,tx,password):
defsign_transaction(self,tx,password):
iftx.is_complete():
iftx.is_complete():
@ -480,6 +485,8 @@ class Ledger_KeyStore(Hardware_KeyStore):
exceptBTChipExceptionase:
exceptBTChipExceptionase:
ife.sw==0x6985:# cancelled by user
ife.sw==0x6985:# cancelled by user
return
return
elife.sw==0x6982:
raise# pin lock. decorator will catch it
else:
else:
traceback.print_exc(file=sys.stderr)
traceback.print_exc(file=sys.stderr)
self.give_error(e,True)
self.give_error(e,True)
@ -494,6 +501,7 @@ class Ledger_KeyStore(Hardware_KeyStore):