transaction: psbt.from_raw_psbt: clarify hex input must be str
What changed, and why it matters
This is a tiny code cleanup in Electrum's transaction handling. The change removes a check that accepted bytes for a hex-encoded PSBT, because Python's bytes.fromhex() only accepts strings anyway. The commit message explicitly says there is no functional change except that bad input now raises a slightly different error. There is no security issue here.
No action required. This is a non-security documentation/type-hint cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch narrows the type annotation and condition in PartialTransaction.from_raw_psbt(). Previously the code checked whether the first 10 characters of ‘raw’ matched the hex magic ‘70736274ff’ as either bytes or str. Since bytes.fromhex() requires a str argument, the bytes branch was unreachable in practice. The patch removes the unreachable bytes comparison and updates the type hint to Union[str, bytes, bytearray] (bytes/bytearray still accepted for base64 input). The commit message states ‘no functional change (besides incorrect input now raising a different exception)’.
Changed components
electrum/transaction.pyPartialTransaction.from_raw_psbtInspect captured patch +2 / −2
diff --git a/electrum/transaction.py b/electrum/transaction.py
index 7f621af..5b1ec4b 100644
--- a/electrum/transaction.py
+++ b/electrum/transaction.py
@@ -2202,9 +2202,9 @@ class PartialTransaction(Transaction):
return res
@classmethod
- def from_raw_psbt(cls, raw) -> 'PartialTransaction':
+ def from_raw_psbt(cls, raw: Union[str, bytes, bytearray]) -> 'PartialTransaction':
# auto-detect and decode Base64 and Hex.
- if raw[0:10].lower() in (b'70736274ff', '70736274ff'): # hex
+ if raw[0:10].lower() == '70736274ff': # hex (str)
raw = bytes.fromhex(raw)
elif raw[0:6] in (b'cHNidP', 'cHNidP'): # base64
raw = base64.b64decode(raw, validate=True)
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.