Consistently name sign_tx psbt argument
What changed, and why it matters
This commit is a simple code cleanup: it renames the argument to the sign_tx method from 'tx' to 'psbt' across five hardware wallet device files. There are no functional changes, no bug fixes, and no security implications.
No security action needed. This is a non-functional refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure identifier rename. In coldcard.py, digitalbitbox.py, jade.py, ledger.py, and trezor.py, the parameter name of the sign_tx method is changed from ‘tx’ to ‘psbt’, and all internal references are updated accordingly. No logic, control flow, data handling, or API behavior is altered.
Changed components
hwilib/devices/coldcard.pyhwilib/devices/digitalbitbox.pyhwilib/devices/jade.pyhwilib/devices/ledger.pyhwilib/devices/trezor.pyInspect captured patch +36 / −36
### hwilib/devices/coldcard.py
@@ -155,7 +155,7 @@ def get_master_fingerprint(self) -> bytes:
return struct.pack('<I', self.device.master_fingerprint)
@coldcard_exception
- def sign_tx(self, tx: PSBT) -> PSBT:
+ def sign_tx(self, psbt: PSBT) -> PSBT:
"""
Sign a transaction with the Coldcard.
@@ -172,7 +172,7 @@ def sign_tx(self, tx: PSBT) -> PSBT:
# For multisigs, we may need to do multiple passes if we appear in an input multiple times
passes = 1
if not self.is_edge:
- for psbt_in in tx.inputs:
+ for psbt_in in psbt.inputs:
our_keys = 0
for key in psbt_in.hd_keypaths.keys():
keypath = psbt_in.hd_keypaths[key]
@@ -181,12 +181,12 @@ def sign_tx(self, tx: PSBT) -> PSBT:
if our_keys > passes:
passes = our_keys
- if tx.version == 2 and not self._supports_psbt_v2():
- tx.convert_to_v0()
+ if psbt.version == 2 and not self._supports_psbt_v2():
+ psbt.convert_to_v0()
for _ in range(passes):
# Get psbt in hex and then make binary
- fd = io.BytesIO(base64.b64decode(tx.serialize()))
+ fd = io.BytesIO(base64.b64decode(psbt.serialize()))
# learn size (portable way)
sz = fd.seek(0, 2)
@@ -232,10 +232,10 @@ def sign_tx(self, tx: PSBT) -> PSBT:
result = self.device.download_file(result_len, result_sha, file_number=1)
- tx = PSBT()
- tx.deserialize(base64.b64encode(result).decode())
+ psbt = PSBT()
+ psbt.deserialize(base64.b64encode(result).decode())
- return tx
+ return psbt
@coldcard_exception
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:
### hwilib/devices/digitalbitbox.py
@@ -391,17 +391,17 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
return xpub
@digitalbitbox_exception
- def sign_tx(self, tx: PSBT) -> PSBT:
+ def sign_tx(self, psbt: PSBT) -> PSBT:
# Create a transaction with all scriptsigs blanked out
- blank_tx = tx.get_unsigned_tx()
+ blank_tx = psbt.get_unsigned_tx()
# Get the master key fingerprint
master_fp = self.get_master_fingerprint()
# create sighashes
sighash_tuples = []
- for txin, psbt_in, i_num in zip(blank_tx.vin, tx.inputs, range(len(blank_tx.vin))):
+ for txin, psbt_in, i_num in zip(blank_tx.vin, psbt.inputs, range(len(blank_tx.vin))):
sighash = b""
utxo = None
if psbt_in.witness_utxo:
@@ -497,7 +497,7 @@ def sign_tx(self, tx: PSBT) -> PSBT:
# Return early if nothing to do
if len(sighash_tuples) == 0:
- return tx
+ return psbt
for i in range(0, len(sighash_tuples), 15):
tups = sighash_tuples[i:i + 15]
@@ -537,9 +537,9 @@ def sign_tx(self, tx: PSBT) -> PSBT:
# add sigs to tx
for tup, sig in zip(tups, der_sigs):
- tx.inputs[tup[2]].partial_sigs[tup[3]] = sig
+ psbt.inputs[tup[2]].partial_sigs[tup[3]] = sig
- return tx
+ return psbt
@digitalbitbox_exception
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:
### hwilib/devices/jade.py
@@ -374,16 +374,16 @@ def _split_at_last_hardened_element(path: Sequence[int]) -> Tuple[Sequence[int],
# Sign tx PSBT - newer Jade firmware supports native PSBT signing, but old firmwares require
# mapping to the legacy 'sign_tx' structures.
@jade_exception
- def sign_tx(self, tx: PSBT) -> PSBT:
+ def sign_tx(self, psbt: PSBT) -> PSBT:
"""
Sign a transaction with the Blockstream Jade.
"""
# Old firmware does not have native PSBT handling - use legacy method
if self.PSBT_SUPPORTED_FW_VERSION > self.fw_version.finalize_version():
- return self.legacy_sign_tx(tx)
+ return self.legacy_sign_tx(psbt)
# Firmware 0.1.47 (March 2023) and later support native PSBT signing
- psbt_b64 = tx.serialize()
+ psbt_b64 = psbt.serialize()
psbt_bytes = base64.b64decode(psbt_b64.strip())
# NOTE: sign_psbt() does not use AE signatures, so sticks with default (rfc6979)
### hwilib/devices/ledger.py
@@ -188,7 +188,7 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
return ExtendedKey.deserialize(xpub_str)
@ledger_exception
- def sign_tx(self, tx: PSBT) -> PSBT:
+ def sign_tx(self, psbt: PSBT) -> PSBT:
"""
Sign a transaction with a Ledger device. Not all transactions can be signed by a Ledger.
@@ -209,20 +209,20 @@ def legacy_sign_tx() -> PSBT:
if not isinstance(client, LegacyClient):
client = LegacyClient(self.transport_client, self.chain)
wallet = WalletPolicy("", "wpkh(@0/**)", [""])
- legacy_input_sigs = client.sign_psbt(tx, wallet, None)
+ legacy_input_sigs = client.sign_psbt(psbt, wallet, None)
for idx, partial_sig in legacy_input_sigs:
- psbt_in = tx.inputs[idx]
+ psbt_in = psbt.inputs[idx]
psbt_in.partial_sigs[partial_sig.pubkey] = partial_sig.signature
- return tx
+ return psbt
if isinstance(self.client, LegacyClient):
return legacy_sign_tx()
# Make a deepcopy of this psbt. We will need to modify it to get signing to work,
# which will affect the caller's detection for whether signing occured.
- psbt2 = copy.deepcopy(tx)
- if tx.version != 2:
+ psbt2 = copy.deepcopy(psbt)
+ if psbt.version != 2:
psbt2.convert_to_v2()
# Figure out which wallets are signing
@@ -374,13 +374,13 @@ def process_origin(origin: KeyOriginInfo) -> None:
psbt_in.partial_sigs[yielded.pubkey] = yielded.signature
# Extract the sigs from psbt2 and put them into tx
- for sig_in, psbt_in in zip(psbt2.inputs, tx.inputs):
+ for sig_in, psbt_in in zip(psbt2.inputs, psbt.inputs):
psbt_in.partial_sigs.update(sig_in.partial_sigs)
psbt_in.tap_script_sigs.update(sig_in.tap_script_sigs)
if len(sig_in.tap_key_sig) != 0 and len(psbt_in.tap_key_sig) == 0:
psbt_in.tap_key_sig = sig_in.tap_key_sig
- return tx
+ return psbt
@ledger_exception
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:
### hwilib/devices/trezor.py
@@ -359,7 +359,7 @@ def get_pubkey_at_path(self, path: str) -> ExtendedKey:
return xpub
@trezor_exception
- def sign_tx(self, tx: PSBT) -> PSBT:
+ def sign_tx(self, psbt: PSBT) -> PSBT:
"""
Sign a transaction with the Trezor. There are some limitations to what transactions can be signed.
@@ -382,7 +382,7 @@ def sign_tx(self, tx: PSBT) -> PSBT:
# Prepare inputs
inputs = []
to_ignore = [] # Note down which inputs whose signatures we're going to ignore
- for input_num, psbt_in in builtins.enumerate(tx.inputs):
+ for input_num, psbt_in in builtins.enumerate(psbt.inputs):
assert psbt_in.prev_txid is not None
assert psbt_in.prev_out is not None
assert psbt_in.sequence is not None
@@ -447,7 +447,7 @@ def ignore_input() -> None:
to_ignore.append(input_num)
# Check for multisig
- is_ms, multisig = parse_multisig(scriptcode, tx.xpub, psbt_in)
+ is_ms, multisig = parse_multisig(scriptcode, psbt.xpub, psbt_in)
if is_ms:
# Add to txinputtype
txinputtype.multisig = multisig
@@ -533,7 +533,7 @@ def ignore_input() -> None:
# prepare outputs
outputs = []
- for psbt_out in tx.outputs:
+ for psbt_out in psbt.outputs:
out = psbt_out.get_txout()
txoutput = messages.TxOutputType(amount=out.nValue)
txoutput.script_type = messages.OutputScriptType.PAYTOADDRESS
@@ -582,7 +582,7 @@ def ignore_input() -> None:
if psbt_out.witness_script or psbt_out.redeem_script:
is_ms, multisig = parse_multisig(
psbt_out.witness_script or psbt_out.redeem_script,
- tx.xpub, psbt_out)
+ psbt.xpub, psbt_out)
if is_ms:
txoutput.multisig = multisig
if not wit:
@@ -593,7 +593,7 @@ def ignore_input() -> None:
# Prepare prev txs
prevtxs = {}
- for psbt_in in tx.inputs:
+ for psbt_in in psbt.inputs:
if psbt_in.non_witness_utxo:
prev = psbt_in.non_witness_utxo
@@ -622,20 +622,20 @@ def ignore_input() -> None:
prevtxs[ser_uint256(psbt_in.non_witness_utxo.sha256)[::-1]] = t
# Sign the transaction
- assert tx.tx_version is not None
+ assert psbt.tx_version is not None
signed_tx = btc.sign_tx(
client=self.client,
coin_name=self.coin_name,
inputs=inputs,
outputs=outputs,
prev_txes=prevtxs,
- version=tx.tx_version,
- lock_time=tx.compute_lock_time(),
+ version=psbt.tx_version,
+ lock_time=psbt.compute_lock_time(),
serialize=False,
)
# Each input has one signature
- for input_num, (psbt_in, sig) in py_enumerate(list(zip(tx.inputs, signed_tx[0]))):
+ for input_num, (psbt_in, sig) in py_enumerate(list(zip(psbt.inputs, signed_tx[0]))):
if input_num in to_ignore:
continue
for pubkey in psbt_in.hd_keypaths.keys():
@@ -650,7 +650,7 @@ def ignore_input() -> None:
p += 1
- return tx
+ return psbt
@trezor_exception
def sign_message(self, message: Union[str, bytes], keypath: str) -> str:Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.