tMerge pull request #2824 from btchip/ledger-segwit-path - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 4d985691d667964959fab2823ce6d46dc73e4a80 DIR parent b86619ee301cf6e2528439064328f2734adeee46 HTML Author: ThomasV <thomasv@electrum.org> Date: Wed, 30 Aug 2017 23:43:10 +0200 Merge pull request #2824 from btchip/ledger-segwit-path Ledger - Python 3 and Segwit fixes Diffstat: M plugins/ledger/auth2fa.py | 11 ++++++----- M plugins/ledger/ledger.py | 9 ++++----- 2 files changed, 10 insertions(+), 10 deletions(-) --- DIR diff --git a/plugins/ledger/auth2fa.py b/plugins/ledger/auth2fa.py t@@ -1,3 +1,4 @@ +from binascii import hexlify, unhexlify import threading from PyQt4.Qt import (QDialog, QInputDialog, QLineEdit, QTextEdit, QVBoxLayout, QLabel, SIGNAL) t@@ -182,7 +183,7 @@ class LedgerAuthDialog(QDialog): def do_pairing(self): rng = os.urandom(16) - pairID = rng.encode('hex') + hashlib.sha256(rng).digest()[0].encode('hex') + pairID = (hexlify(rng) + hexlify(hashlib.sha256(rng).digest()[0:1])).decode('utf-8') self.pairqr.setData(pairID) self.modebox.setVisible(False) self.helpmsg.setVisible(False) t@@ -245,7 +246,7 @@ class LedgerWebSocket(QThread): QThread.__init__(self) self.stopping = False self.pairID = pairID - self.txreq = '{"type":"request","second_factor_data":"' + str(txdata['secureScreenData']).encode('hex') + '"}' if txdata else None + self.txreq = '{"type":"request","second_factor_data":"' + hexlify(txdata['secureScreenData']).decode('utf-8') + '"}' if txdata else None self.dlg = dlg self.dongle = self.dlg.dongle self.data = None t@@ -269,10 +270,10 @@ class LedgerWebSocket(QThread): if data['type'] == 'identify': debug_msg('Identify') apdu = [0xe0, 0x12, 0x01, 0x00, 0x41] # init pairing - apdu.extend(data['public_key'].decode('hex')) + apdu.extend(unhexlify(data['public_key'])) try: challenge = self.dongle.exchange( bytearray(apdu) ) - ws.send( '{"type":"challenge","data":"%s" }' % str(challenge).encode('hex') ) + ws.send( '{"type":"challenge","data":"%s" }' % hexlify(challenge).decode('utf-8') ) self.data = data except BTChipException as e: debug_msg('Identify Failed') t@@ -280,7 +281,7 @@ class LedgerWebSocket(QThread): if data['type'] == 'challenge': debug_msg('Challenge') apdu = [0xe0, 0x12, 0x02, 0x00, 0x10] # confirm pairing - apdu.extend(data['data'].decode('hex')) + apdu.extend(unhexlify(data['data'])) try: self.dongle.exchange( bytearray(apdu) ) debug_msg('Pairing Successful') DIR diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py t@@ -1,4 +1,3 @@ -from binascii import hexlify from struct import pack, unpack import hashlib import time t@@ -175,8 +174,8 @@ class Ledger_KeyStore(Hardware_KeyStore): self.cfg = d.get('cfg', {'mode':0,'pair':''}) def is_segwit(self): - return self.plugin.segwit - + return self.derivation.startswith("m/49'/") + def dump(self): obj = Hardware_KeyStore.dump(self) obj['cfg'] = self.cfg t@@ -341,10 +340,10 @@ class Ledger_KeyStore(Hardware_KeyStore): for utxo in inputs: sequence = int_to_hex(utxo[5], 4) if segwitTransaction: - txtmp = bitcoinTransaction(bfh(utxo[0])) + txtmp = bitcoinTransaction(bfh(utxo[0])) tmp = bfh(utxo[3])[::-1] tmp += bfh(int_to_hex(utxo[1], 4)) - tmp += str(txtmp.outputs[utxo[1]].amount) + tmp += txtmp.outputs[utxo[1]].amount chipInputs.append({'value' : tmp, 'witness' : True, 'sequence' : sequence}) redeemScripts.append(bfh(utxo[2])) elif not p2shTransaction: