move blinding_privkey from onion_message to lnonion
This commit is contained in:
committed by
f321x
parent
3e3bffa4a2
commit
9bcbbdd3eb
@@ -193,6 +193,17 @@ def get_blinded_node_id(node_id: bytes, shared_secret: bytes):
|
|||||||
return blinded_node_id.get_public_key_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(
|
def new_onion_packet(
|
||||||
payment_path_pubkeys: Sequence[bytes],
|
payment_path_pubkeys: Sequence[bytes],
|
||||||
session_key: bytes,
|
session_key: bytes,
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ from electrum.lnrouter import PathEdge
|
|||||||
from electrum.logging import get_logger, Logger
|
from electrum.logging import get_logger, Logger
|
||||||
from electrum.crypto import sha256, get_ecdh
|
from electrum.crypto import sha256, get_ecdh
|
||||||
from electrum.lnmsg import OnionWireSerializer
|
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,
|
OnionHopsDataSingle, decrypt_onionmsg_data_tlv, encrypt_onionmsg_data_tlv,
|
||||||
get_shared_secrets_along_route, new_onion_packet, encrypt_hops_recipient_data)
|
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
|
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()
|
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:
|
def is_onion_message_node(node_id: bytes, node_info: Optional['NodeInfo']) -> bool:
|
||||||
if not node_info:
|
if not node_info:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ from electrum.lnmsg import decode_msg, OnionWireSerializer
|
|||||||
from electrum.lnonion import (
|
from electrum.lnonion import (
|
||||||
OnionHopsDataSingle, OnionPacket, process_onion_packet, get_bolt04_onion_key, encrypt_onionmsg_data_tlv,
|
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,
|
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.crypto import get_ecdh, privkey_to_pubkey
|
||||||
from electrum.lntransport import LNPeerAddr
|
from electrum.lntransport import LNPeerAddr
|
||||||
from electrum.lnutil import LnFeatures, Keypair, MIN_FINAL_CLTV_DELTA_ACCEPTED, REMOTE
|
from electrum.lnutil import LnFeatures, Keypair, MIN_FINAL_CLTV_DELTA_ACCEPTED, REMOTE
|
||||||
from electrum.onion_message import (
|
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.util import bfh, read_json_file, OldTaskGroup, get_asyncio_loop
|
||||||
from electrum.logging import console_stderr_handler
|
from electrum.logging import console_stderr_handler
|
||||||
|
|||||||
Reference in New Issue
Block a user