move blinding_privkey from onion_message to lnonion
What changed, and why it matters
This commit simply moves an existing helper function called blinding_privkey from one file (onion_message.py) to another (lnonion.py) and updates the import statements and tests accordingly. There is no change to what the function does, no bug fix, and no security patch.
No security action needed; this is a code-cleanup refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure refactor: the blinding_privkey implementation is relocated from electrum/onion_message.py to electrum/lnonion.py. The function body is identical, and onion_message.py now imports it from lnonion.py. The test file’s imports are updated to match. No functional or cryptographic changes are present.
Changed components
electrum/lnonion.pyelectrum/onion_message.pytests/test_onion_message.pyInspect captured patch +14 / −15
diff --git a/electrum/lnonion.py b/electrum/lnonion.py
index 10fb229..a334fee 100644
--- a/electrum/lnonion.py
+++ b/electrum/lnonion.py
@@ -193,6 +193,17 @@ def get_blinded_node_id(node_id: bytes, shared_secret: bytes):
return blinded_node_id.get_public_key_bytes()
+def blinding_privkey(privkey: bytes, blinding: bytes) -> bytes:
+ shared_secret = get_ecdh(privkey, blinding)
+ b_hmac = get_bolt04_onion_key(b'blinded_node_id', shared_secret)
+ b_hmac_int = int.from_bytes(b_hmac, byteorder="big")
+
+ our_privkey_int = int.from_bytes(privkey, byteorder="big")
+ our_privkey_int = our_privkey_int * b_hmac_int % ecc.CURVE_ORDER
+ our_privkey = our_privkey_int.to_bytes(32, byteorder="big")
+ return our_privkey
+
+
def new_onion_packet(
payment_path_pubkeys: Sequence[bytes],
session_key: bytes,
diff --git a/electrum/onion_message.py b/electrum/onion_message.py
index e200aed..8e4baff 100644
--- a/electrum/onion_message.py
+++ b/electrum/onion_message.py
@@ -40,7 +40,7 @@ from electrum.lnrouter import PathEdge
from electrum.logging import get_logger, Logger
from electrum.crypto import sha256, get_ecdh
from electrum.lnmsg import OnionWireSerializer
-from electrum.lnonion import (get_bolt04_onion_key, OnionPacket, process_onion_packet,
+from electrum.lnonion import (get_bolt04_onion_key, OnionPacket, process_onion_packet, blinding_privkey,
OnionHopsDataSingle, decrypt_onionmsg_data_tlv, encrypt_onionmsg_data_tlv,
get_shared_secrets_along_route, new_onion_packet, encrypt_hops_recipient_data)
from electrum.lnutil import LnFeatures, MIN_FINAL_CLTV_DELTA_ACCEPTED, MAXIMUM_REMOTE_TO_SELF_DELAY_ACCEPTED
@@ -145,18 +145,6 @@ def encode_blinded_path(blinded_path: dict):
return blinded_path_fd.getvalue()
-def blinding_privkey(privkey: bytes, blinding: bytes) -> bytes:
- shared_secret = get_ecdh(privkey, blinding)
- b_hmac = get_bolt04_onion_key(b'blinded_node_id', shared_secret)
- b_hmac_int = int.from_bytes(b_hmac, byteorder="big")
-
- our_privkey_int = int.from_bytes(privkey, byteorder="big")
- our_privkey_int = our_privkey_int * b_hmac_int % ecc.CURVE_ORDER
- our_privkey = our_privkey_int.to_bytes(32, byteorder="big")
-
- return our_privkey
-
-
def is_onion_message_node(node_id: bytes, node_info: Optional['NodeInfo']) -> bool:
if not node_info:
return False
diff --git a/tests/test_onion_message.py b/tests/test_onion_message.py
index dd2be43..d261bbe 100644
--- a/tests/test_onion_message.py
+++ b/tests/test_onion_message.py
@@ -17,12 +17,12 @@ from electrum.lnmsg import decode_msg, OnionWireSerializer
from electrum.lnonion import (
OnionHopsDataSingle, OnionPacket, process_onion_packet, get_bolt04_onion_key, encrypt_onionmsg_data_tlv,
get_shared_secrets_along_route, new_onion_packet, ONION_MESSAGE_LARGE_SIZE, HOPS_DATA_SIZE, InvalidPayloadSize,
- encrypt_hops_recipient_data)
+ encrypt_hops_recipient_data, blinding_privkey)
from electrum.crypto import get_ecdh, privkey_to_pubkey
from electrum.lntransport import LNPeerAddr
from electrum.lnutil import LnFeatures, Keypair, MIN_FINAL_CLTV_DELTA_ACCEPTED, REMOTE
from electrum.onion_message import (
- blinding_privkey, create_blinded_path,OnionMessageManager, NoRouteFound, Timeout, get_blinded_paths_to_me,
+ create_blinded_path, OnionMessageManager, NoRouteFound, Timeout, get_blinded_paths_to_me,
)
from electrum.util import bfh, read_json_file, OldTaskGroup, get_asyncio_loop
from electrum.logging import console_stderr_handler
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.