lnonion: (trivial) make OnionPacket.__init__ kw-only
What changed, and why it matters
This is a tiny code-style change that forces callers to name each argument when creating an OnionPacket object. It does not change what the code does, only how callers must write their arguments. There is no security issue here.
No action needed. This is a trivial, non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds a single asterisk (*) before the parameters of OnionPacket.init, making all arguments keyword-only in Python. This prevents positional calls like OnionPacket(pk, data, mac) and requires OnionPacket(public_key=pk, hops_data=data, hmac=mac). The assertions and logic inside the constructor are unchanged. No security vulnerability is introduced or fixed.
Changed components
electrum/lnonion.py: OnionPacket.__init__Inspect captured patch +1 / −1
diff --git a/electrum/lnonion.py b/electrum/lnonion.py
index b80c882..67edaf5 100644
--- a/electrum/lnonion.py
+++ b/electrum/lnonion.py
@@ -114,7 +114,7 @@ class OnionHopsDataSingle: # called HopData in lnd
class OnionPacket:
- def __init__(self, public_key: bytes, hops_data: bytes, hmac: bytes, version: int = 0):
+ def __init__(self, *, public_key: bytes, hops_data: bytes, hmac: bytes, version: int = 0):
assert len(public_key) == 33
assert len(hops_data) in [HOPS_DATA_SIZE, TRAMPOLINE_HOPS_DATA_SIZE, ONION_MESSAGE_LARGE_SIZE]
assert len(hmac) == PER_HOP_HMAC_SIZE
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.