Skip to content

Commit 04b9a48

Browse files
committed
Consistently name sign_tx psbt argument
1 parent 3f2b2b2 commit 04b9a48

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

hwilib/devices/coldcard.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_master_fingerprint(self) -> bytes:
116116
return struct.pack('<I', self.device.master_fingerprint)
117117

118118
@coldcard_exception
119-
def sign_tx(self, tx: PSBT) -> PSBT:
119+
def sign_tx(self, psbt: PSBT) -> PSBT:
120120
"""
121121
Sign a transaction with the Coldcard.
122122
@@ -132,7 +132,7 @@ def sign_tx(self, tx: PSBT) -> PSBT:
132132

133133
# For multisigs, we may need to do multiple passes if we appear in an input multiple times
134134
passes = 1
135-
for psbt_in in tx.inputs:
135+
for psbt_in in psbt.inputs:
136136
our_keys = 0
137137
for key in psbt_in.hd_keypaths.keys():
138138
keypath = psbt_in.hd_keypaths[key]
@@ -143,8 +143,8 @@ def sign_tx(self, tx: PSBT) -> PSBT:
143143

144144
for _ in range(passes):
145145
# Get psbt in hex and then make binary
146-
tx.convert_to_v0()
147-
fd = io.BytesIO(base64.b64decode(tx.serialize()))
146+
psbt.convert_to_v0()
147+
fd = io.BytesIO(base64.b64decode(psbt.serialize()))
148148

149149
# learn size (portable way)
150150
sz = fd.seek(0, 2)
@@ -190,10 +190,10 @@ def sign_tx(self, tx: PSBT) -> PSBT:
190190

191191
result = self.device.download_file(result_len, result_sha, file_number=1)
192192

193-
tx = PSBT()
194-
tx.deserialize(base64.b64encode(result).decode())
193+
psbt = PSBT()
194+
psbt.deserialize(base64.b64encode(result).decode())
195195

196-
return tx
196+
return psbt
197197

198198
@coldcard_exception
199199
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:

hwilib/devices/digitalbitbox.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,17 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
387387
return xpub
388388

389389
@digitalbitbox_exception
390-
def sign_tx(self, tx: PSBT) -> PSBT:
390+
def sign_tx(self, psbt: PSBT) -> PSBT:
391391

392392
# Create a transaction with all scriptsigs blanked out
393-
blank_tx = tx.get_unsigned_tx()
393+
blank_tx = psbt.get_unsigned_tx()
394394

395395
# Get the master key fingerprint
396396
master_fp = self.get_master_fingerprint()
397397

398398
# create sighashes
399399
sighash_tuples = []
400-
for txin, psbt_in, i_num in zip(blank_tx.vin, tx.inputs, range(len(blank_tx.vin))):
400+
for txin, psbt_in, i_num in zip(blank_tx.vin, psbt.inputs, range(len(blank_tx.vin))):
401401
sighash = b""
402402
utxo = None
403403
if psbt_in.witness_utxo:
@@ -493,7 +493,7 @@ def sign_tx(self, tx: PSBT) -> PSBT:
493493

494494
# Return early if nothing to do
495495
if len(sighash_tuples) == 0:
496-
return tx
496+
return psbt
497497

498498
for i in range(0, len(sighash_tuples), 15):
499499
tups = sighash_tuples[i:i + 15]
@@ -533,9 +533,9 @@ def sign_tx(self, tx: PSBT) -> PSBT:
533533

534534
# add sigs to tx
535535
for tup, sig in zip(tups, der_sigs):
536-
tx.inputs[tup[2]].partial_sigs[tup[3]] = sig
536+
psbt.inputs[tup[2]].partial_sigs[tup[3]] = sig
537537

538-
return tx
538+
return psbt
539539

540540
@digitalbitbox_exception
541541
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:

hwilib/devices/jade.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,16 @@ def _split_at_last_hardened_element(path: Sequence[int]) -> Tuple[Sequence[int],
370370
# Sign tx PSBT - newer Jade firmware supports native PSBT signing, but old firmwares require
371371
# mapping to the legacy 'sign_tx' structures.
372372
@jade_exception
373-
def sign_tx(self, tx: PSBT) -> PSBT:
373+
def sign_tx(self, psbt: PSBT) -> PSBT:
374374
"""
375375
Sign a transaction with the Blockstream Jade.
376376
"""
377377
# Old firmware does not have native PSBT handling - use legacy method
378378
if self.PSBT_SUPPORTED_FW_VERSION > self.fw_version.finalize_version():
379-
return self.legacy_sign_tx(tx)
379+
return self.legacy_sign_tx(psbt)
380380

381381
# Firmware 0.1.47 (March 2023) and later support native PSBT signing
382-
psbt_b64 = tx.serialize()
382+
psbt_b64 = psbt.serialize()
383383
psbt_bytes = base64.b64decode(psbt_b64.strip())
384384

385385
# NOTE: sign_psbt() does not use AE signatures, so sticks with default (rfc6979)

hwilib/devices/ledger.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
185185
return ExtendedKey.deserialize(xpub_str)
186186

187187
@ledger_exception
188-
def sign_tx(self, tx: PSBT) -> PSBT:
188+
def sign_tx(self, psbt: PSBT) -> PSBT:
189189
"""
190190
Sign a transaction with a Ledger device. Not all transactions can be signed by a Ledger.
191191
@@ -206,20 +206,20 @@ def legacy_sign_tx() -> PSBT:
206206
if not isinstance(client, LegacyClient):
207207
client = LegacyClient(self.transport_client, self.chain)
208208
wallet = WalletPolicy("", "wpkh(@0/**)", [""])
209-
legacy_input_sigs = client.sign_psbt(tx, wallet, None)
209+
legacy_input_sigs = client.sign_psbt(psbt, wallet, None)
210210

211211
for idx, pubkey, sig in legacy_input_sigs:
212-
psbt_in = tx.inputs[idx]
212+
psbt_in = psbt.inputs[idx]
213213
psbt_in.partial_sigs[pubkey] = sig
214-
return tx
214+
return psbt
215215

216216
if isinstance(self.client, LegacyClient):
217217
return legacy_sign_tx()
218218

219219
# Make a deepcopy of this psbt. We will need to modify it to get signing to work,
220220
# which will affect the caller's detection for whether signing occured.
221-
psbt2 = copy.deepcopy(tx)
222-
if tx.version != 2:
221+
psbt2 = copy.deepcopy(psbt)
222+
if psbt.version != 2:
223223
psbt2.convert_to_v2()
224224

225225
# Figure out which wallets are signing
@@ -369,13 +369,13 @@ def process_origin(origin: KeyOriginInfo) -> None:
369369
psbt_in.partial_sigs[pubkey] = sig
370370

371371
# Extract the sigs from psbt2 and put them into tx
372-
for sig_in, psbt_in in zip(psbt2.inputs, tx.inputs):
372+
for sig_in, psbt_in in zip(psbt2.inputs, psbt.inputs):
373373
psbt_in.partial_sigs.update(sig_in.partial_sigs)
374374
psbt_in.tap_script_sigs.update(sig_in.tap_script_sigs)
375375
if len(sig_in.tap_key_sig) != 0 and len(psbt_in.tap_key_sig) == 0:
376376
psbt_in.tap_key_sig = sig_in.tap_key_sig
377377

378-
return tx
378+
return psbt
379379

380380
@ledger_exception
381381
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:

hwilib/devices/trezor.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
355355
return xpub
356356

357357
@trezor_exception
358-
def sign_tx(self, tx: PSBT) -> PSBT:
358+
def sign_tx(self, psbt: PSBT) -> PSBT:
359359
"""
360360
Sign a transaction with the Trezor. There are some limitations to what transactions can be signed.
361361
@@ -378,7 +378,7 @@ def sign_tx(self, tx: PSBT) -> PSBT:
378378
# Prepare inputs
379379
inputs = []
380380
to_ignore = [] # Note down which inputs whose signatures we're going to ignore
381-
for input_num, psbt_in in builtins.enumerate(tx.inputs):
381+
for input_num, psbt_in in builtins.enumerate(psbt.inputs):
382382
assert psbt_in.prev_txid is not None
383383
assert psbt_in.prev_out is not None
384384
assert psbt_in.sequence is not None
@@ -443,7 +443,7 @@ def ignore_input() -> None:
443443
to_ignore.append(input_num)
444444

445445
# Check for multisig
446-
is_ms, multisig = parse_multisig(scriptcode, tx.xpub, psbt_in)
446+
is_ms, multisig = parse_multisig(scriptcode, psbt.xpub, psbt_in)
447447
if is_ms:
448448
# Add to txinputtype
449449
txinputtype.multisig = multisig
@@ -529,7 +529,7 @@ def ignore_input() -> None:
529529

530530
# prepare outputs
531531
outputs = []
532-
for psbt_out in tx.outputs:
532+
for psbt_out in psbt.outputs:
533533
out = psbt_out.get_txout()
534534
txoutput = messages.TxOutputType(amount=out.nValue)
535535
txoutput.script_type = messages.OutputScriptType.PAYTOADDRESS
@@ -578,7 +578,7 @@ def ignore_input() -> None:
578578
if psbt_out.witness_script or psbt_out.redeem_script:
579579
is_ms, multisig = parse_multisig(
580580
psbt_out.witness_script or psbt_out.redeem_script,
581-
tx.xpub, psbt_out)
581+
psbt.xpub, psbt_out)
582582
if is_ms:
583583
txoutput.multisig = multisig
584584
if not wit:
@@ -589,7 +589,7 @@ def ignore_input() -> None:
589589

590590
# Prepare prev txs
591591
prevtxs = {}
592-
for psbt_in in tx.inputs:
592+
for psbt_in in psbt.inputs:
593593
if psbt_in.non_witness_utxo:
594594
prev = psbt_in.non_witness_utxo
595595

@@ -618,20 +618,20 @@ def ignore_input() -> None:
618618
prevtxs[ser_uint256(psbt_in.non_witness_utxo.sha256)[::-1]] = t
619619

620620
# Sign the transaction
621-
assert tx.tx_version is not None
621+
assert psbt.tx_version is not None
622622
signed_tx = btc.sign_tx(
623623
client=self.client,
624624
coin_name=self.coin_name,
625625
inputs=inputs,
626626
outputs=outputs,
627627
prev_txes=prevtxs,
628-
version=tx.tx_version,
629-
lock_time=tx.compute_lock_time(),
628+
version=psbt.tx_version,
629+
lock_time=psbt.compute_lock_time(),
630630
serialize=False,
631631
)
632632

633633
# Each input has one signature
634-
for input_num, (psbt_in, sig) in py_enumerate(list(zip(tx.inputs, signed_tx[0]))):
634+
for input_num, (psbt_in, sig) in py_enumerate(list(zip(psbt.inputs, signed_tx[0]))):
635635
if input_num in to_ignore:
636636
continue
637637
for pubkey in psbt_in.hd_keypaths.keys():
@@ -646,7 +646,7 @@ def ignore_input() -> None:
646646

647647
p += 1
648648

649-
return tx
649+
return psbt
650650

651651
@trezor_exception
652652
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:

0 commit comments

Comments
 (0)