tledger: offline signing for segwit inputs - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 530980ea37b9627b0ab26b63acc8866b799b23bc DIR parent 40e9e8bd632bd3d600d8913788221d60a3801cc1 HTML Author: SomberNight <somber.night@protonmail.com> Date: Sat, 28 Apr 2018 22:56:53 +0200 ledger: offline signing for segwit inputs related: #3302 Diffstat: M plugins/ledger/ledger.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) --- DIR diff --git a/plugins/ledger/ledger.py b/plugins/ledger/ledger.py t@@ -356,10 +356,17 @@ class Ledger_KeyStore(Hardware_KeyStore): self.give_error("No matching x_key for sign_transaction") # should never happen redeemScript = Transaction.get_preimage_script(txin) - if txin.get('prev_tx') is None: # and not Transaction.is_segwit_input(txin): - # note: offline signing does not work atm even with segwit inputs for ledger - raise Exception(_('Offline signing with {} is not supported.').format(self.device)) - inputs.append([txin['prev_tx'].raw, txin['prevout_n'], redeemScript, txin['prevout_hash'], signingPos, txin.get('sequence', 0xffffffff - 1) ]) + txin_prev_tx = txin.get('prev_tx') + if txin_prev_tx is None and not Transaction.is_segwit_input(txin): + raise Exception(_('Offline signing with {} is not supported for legacy inputs.').format(self.device)) + txin_prev_tx_raw = txin_prev_tx.raw if txin_prev_tx else None + inputs.append([txin_prev_tx_raw, + txin['prevout_n'], + redeemScript, + txin['prevout_hash'], + signingPos, + txin.get('sequence', 0xffffffff - 1), + txin.get('value')]) inputsPaths.append(hwAddress) pubKeys.append(pubkeys) t@@ -401,10 +408,9 @@ class Ledger_KeyStore(Hardware_KeyStore): for utxo in inputs: sequence = int_to_hex(utxo[5], 4) if segwitTransaction: - txtmp = bitcoinTransaction(bfh(utxo[0])) tmp = bfh(utxo[3])[::-1] tmp += bfh(int_to_hex(utxo[1], 4)) - tmp += txtmp.outputs[utxo[1]].amount + tmp += bfh(int_to_hex(utxo[6], 8)) # txin['value'] chipInputs.append({'value' : tmp, 'witness' : True, 'sequence' : sequence}) redeemScripts.append(bfh(utxo[2])) elif not p2shTransaction: