Add creation wizard, prepare for 1.4.9
This commit is contained in:
parent
11961ae811
commit
af7cc78075
|
@ -25,6 +25,8 @@ try:
|
||||||
from btchip.btchip import btchip
|
from btchip.btchip import btchip
|
||||||
from btchip.btchipUtils import compress_public_key,format_transaction, get_regular_input_script
|
from btchip.btchipUtils import compress_public_key,format_transaction, get_regular_input_script
|
||||||
from btchip.bitcoinTransaction import bitcoinTransaction
|
from btchip.bitcoinTransaction import bitcoinTransaction
|
||||||
|
from btchip.btchipPersoWizard import StartBTChipPersoDialog
|
||||||
|
from btchip.btchipException import BTChipException
|
||||||
BTCHIP = True
|
BTCHIP = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
BTCHIP = False
|
BTCHIP = False
|
||||||
|
@ -139,6 +141,19 @@ class BTChipWallet(NewWallet):
|
||||||
if int(firmware[2]) < 8:
|
if int(firmware[2]) < 8:
|
||||||
aborted = True
|
aborted = True
|
||||||
give_error("Please update your firmware - 1.4.8 or higher is necessary")
|
give_error("Please update your firmware - 1.4.8 or higher is necessary")
|
||||||
|
try:
|
||||||
|
self.client.getOperationMode()
|
||||||
|
except BTChipException,e:
|
||||||
|
if (e.sw == 0x6985):
|
||||||
|
d.close()
|
||||||
|
dialog = StartBTChipPersoDialog()
|
||||||
|
dialog.exec_()
|
||||||
|
# Then fetch the reference again as it was invalidated
|
||||||
|
d = getDongle(True)
|
||||||
|
d.setWaitImpl(DongleWaitQT(d))
|
||||||
|
self.client = btchip(d)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
if not noPin:
|
if not noPin:
|
||||||
# Immediately prompts for the PIN
|
# Immediately prompts for the PIN
|
||||||
confirmed, p, pin = self.password_dialog("Enter your BTChip PIN")
|
confirmed, p, pin = self.password_dialog("Enter your BTChip PIN")
|
||||||
|
@ -148,6 +163,7 @@ class BTChipWallet(NewWallet):
|
||||||
pin = pin.encode()
|
pin = pin.encode()
|
||||||
self.client.verifyPin(pin)
|
self.client.verifyPin(pin)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
self.client = None
|
||||||
if not aborted:
|
if not aborted:
|
||||||
give_error("Could not connect to your BTChip dongle. Please verify access permissions or PIN")
|
give_error("Could not connect to your BTChip dongle. Please verify access permissions or PIN")
|
||||||
else:
|
else:
|
||||||
|
@ -159,14 +175,12 @@ class BTChipWallet(NewWallet):
|
||||||
|
|
||||||
def address_id(self, address):
|
def address_id(self, address):
|
||||||
account_id, (change, address_index) = self.get_address_index(address)
|
account_id, (change, address_index) = self.get_address_index(address)
|
||||||
# FIXME review
|
|
||||||
return "44'/0'/%s'/%d/%d" % (account_id, change, address_index)
|
return "44'/0'/%s'/%d/%d" % (account_id, change, address_index)
|
||||||
|
|
||||||
def create_main_account(self, password):
|
def create_main_account(self, password):
|
||||||
self.create_account('Main account', None) #name, empty password
|
self.create_account('Main account', None) #name, empty password
|
||||||
|
|
||||||
def derive_xkeys(self, root, derivation, password):
|
def derive_xkeys(self, root, derivation, password):
|
||||||
# FIXME review
|
|
||||||
derivation = derivation.replace(self.root_name,"44'/0'/")
|
derivation = derivation.replace(self.root_name,"44'/0'/")
|
||||||
xpub = self.get_public_key(derivation)
|
xpub = self.get_public_key(derivation)
|
||||||
return xpub, None
|
return xpub, None
|
||||||
|
@ -245,6 +259,7 @@ class BTChipWallet(NewWallet):
|
||||||
finally:
|
finally:
|
||||||
if waitDialog.waiting:
|
if waitDialog.waiting:
|
||||||
waitDialog.emit(SIGNAL('dongle_done'))
|
waitDialog.emit(SIGNAL('dongle_done'))
|
||||||
|
self.client.bad = True
|
||||||
|
|
||||||
# Parse the ASN.1 signature
|
# Parse the ASN.1 signature
|
||||||
|
|
||||||
|
@ -261,6 +276,9 @@ class BTChipWallet(NewWallet):
|
||||||
|
|
||||||
# And convert it
|
# And convert it
|
||||||
|
|
||||||
|
#Optimization for 1.4.9+
|
||||||
|
#return b64encode(chr(27 + 4 + (signature[0] & 0x01)) + r + s)
|
||||||
|
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
sig = b64encode( chr(27 + i + 4) + r + s)
|
sig = b64encode( chr(27 + i + 4) + r + s)
|
||||||
try:
|
try:
|
||||||
|
@ -268,8 +286,10 @@ class BTChipWallet(NewWallet):
|
||||||
return sig
|
return sig
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
raise Exception("error: cannot sign message")
|
raise Exception("error: cannot sign message")
|
||||||
|
return b64encode(chr(27 + 4 + (signature[0] & 0x01)) + r + s)
|
||||||
|
|
||||||
|
|
||||||
def choose_tx_inputs( self, amount, fixed_fee, num_outputs, domain = None, coins = None ):
|
def choose_tx_inputs( self, amount, fixed_fee, num_outputs, domain = None, coins = None ):
|
||||||
# Overloaded to get the fee, as BTChip recomputes the change amount
|
# Overloaded to get the fee, as BTChip recomputes the change amount
|
||||||
|
@ -293,6 +313,7 @@ class BTChipWallet(NewWallet):
|
||||||
outputAmount = None
|
outputAmount = None
|
||||||
use2FA = False
|
use2FA = False
|
||||||
aborted = False
|
aborted = False
|
||||||
|
pin = ""
|
||||||
# Fetch inputs of the transaction to sign
|
# Fetch inputs of the transaction to sign
|
||||||
for txinput in tx.inputs:
|
for txinput in tx.inputs:
|
||||||
if ('is_coinbase' in txinput and txinput['is_coinbase']):
|
if ('is_coinbase' in txinput and txinput['is_coinbase']):
|
||||||
|
@ -353,8 +374,10 @@ class BTChipWallet(NewWallet):
|
||||||
waitDialog.start("Signing ...")
|
waitDialog.start("Signing ...")
|
||||||
else:
|
else:
|
||||||
# Sign input with the provided PIN
|
# Sign input with the provided PIN
|
||||||
signatures.append(self.get_client().untrustedHashSign(inputsPaths[inputIndex],
|
inputSignature = self.get_client().untrustedHashSign(inputsPaths[inputIndex],
|
||||||
pin))
|
pin)
|
||||||
|
inputSignature[0] = 0x30 # force for 1.4.9+
|
||||||
|
signatures.append(inputSignature)
|
||||||
inputIndex = inputIndex + 1
|
inputIndex = inputIndex + 1
|
||||||
firstTransaction = False
|
firstTransaction = False
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
|
Loading…
Reference in New Issue